indexing

Why use the INCLUDE clause when creating an index?

孤街醉人 提交于 2020-03-07 05:16:25
问题 While studying for the 70-433 exam I noticed you can create a covering index in one of the following two ways. CREATE INDEX idx1 ON MyTable (Col1, Col2, Col3) -- OR -- CREATE INDEX idx1 ON MyTable (Col1) INCLUDE (Col2, Col3) The INCLUDE clause is new to me. Why would you use it and what guidelines would you suggest in determining whether to create a covering index with or without the INCLUDE clause? 回答1: If the column is not in the WHERE/JOIN/GROUP BY/ORDER BY , but only in the column list in

How Mongo Query planner choose his index

喜你入骨 提交于 2020-03-05 07:47:28
问题 Mongo version : 3.4.3-10-g865d2fb I have a request like this : db.getCollection('c_zop_operations').find({ "a":{ "$in":[ "O", "S", "P" ] }, "$or":[ { "b":"008091", "c":"1187", "d":"F", "e":ISODate("2018-07-22T22:00:00.000Z") }, ... x 39 elements in $or statement ] }).explain("executionStats") The request during 16 seconds and explain returns these results : 155769 documents parse in index !!! { "queryPlanner" : { "plannerVersion" : 1, ... "indexFilterSet" : false, "parsedQuery" : { ... },

python - use if statement to check if entry is already in a list

南楼画角 提交于 2020-03-05 03:14:14
问题 I have a list of list of float lists and I want to test if a value pair (e.g. [2.0, 1.1]) is already in this list. Therefor I wrote a simple code to check this. As far as I understand my code it should always write the result array. I think the if statement is not correct formulated or is at least not doing what I intended to do. The result array should be look like: [0, 1, 2]. It is like a 'self-check'. import numpy as np array_a = np.asarray([[2.0, 1.1], [3.3, 4.4], [2.5, 3.0]]) array_a

Unable to improve query performance in postgresql

余生长醉 提交于 2020-03-04 17:12:03
问题 I am trying to join 9 tables together. The count and index of each tables are given below along with the query. Green color in screenshot indicates keys used to join. But please note that I have used another column for visit_occurrence table called visit_occurrence_id to join but it's not indexed DROP MATERIALIZED VIEW IF EXISTS cdm.dummy CASCADE; CREATE MATERIALIZED VIEW cdm.dummy as select f.person_id,f.gender_id from cdm.visit_occurrence a left join cdm.condition_occurrence b on a.person

Unable to improve query performance in postgresql

安稳与你 提交于 2020-03-04 17:10:19
问题 I am trying to join 9 tables together. The count and index of each tables are given below along with the query. Green color in screenshot indicates keys used to join. But please note that I have used another column for visit_occurrence table called visit_occurrence_id to join but it's not indexed DROP MATERIALIZED VIEW IF EXISTS cdm.dummy CASCADE; CREATE MATERIALIZED VIEW cdm.dummy as select f.person_id,f.gender_id from cdm.visit_occurrence a left join cdm.condition_occurrence b on a.person

What index should I use when using JOIN on PRIMARY KEY

ぐ巨炮叔叔 提交于 2020-02-25 04:16:59
问题 I'm trying to optimise the following MySQL query SELECT Hotel.HotelId, Hotel.Name, Hotel.Enabled, Hotel.IsClosed, HotelRoom.HotelId, HotelRoom.RoomId, HotelRoom.Name AS RoomName FROM Hotel INNER JOIN HotelRoom ON Hotel.HotelId = HotelRoom.HotelId WHERE Hotel.IsClosed = 0 AND Hotel.Enabled = 1 AND HotelRoom.Deleted = 0 AND HotelRoom.Enabled = 1 AND IF(LENGTH(TRIM(sAuxiliaryIds)) > 0 AND sAuxiliaryIds IS NOT NULL, FIND_IN_SET(Hotel.AuxiliaryId, sAuxiliaryIds), 1=1) > 0 ORDER BY Hotel.HotelId

Improve PostgresSQL aggregation query performance

╄→гoц情女王★ 提交于 2020-02-23 10:10:22
问题 I am aggregating data from a Postgres table, the query is taking approx 2 seconds which I want to reduce to less than a second. Please find below the execution details: Query select a.search_keyword, hll_cardinality( hll_union_agg(a.users) ):: int as user_count, hll_cardinality( hll_union_agg(a.sessions) ):: int as session_count, sum(a.total) as keyword_count from rollup_day a where a.created_date between '2018-09-01' and '2019-09-30' and a.tenant_id = '62850a62-19ac-477d-9cd7-837f3d716885'

Improve PostgresSQL aggregation query performance

試著忘記壹切 提交于 2020-02-23 10:09:39
问题 I am aggregating data from a Postgres table, the query is taking approx 2 seconds which I want to reduce to less than a second. Please find below the execution details: Query select a.search_keyword, hll_cardinality( hll_union_agg(a.users) ):: int as user_count, hll_cardinality( hll_union_agg(a.sessions) ):: int as session_count, sum(a.total) as keyword_count from rollup_day a where a.created_date between '2018-09-01' and '2019-09-30' and a.tenant_id = '62850a62-19ac-477d-9cd7-837f3d716885'

How to create indexes on multiple columns

谁说胖子不能爱 提交于 2020-02-15 13:48:11
问题 We have the following entity relationships where a User belongs to a particular Organization. My queries either look like "select * from User where org=:org" or "select * from User where org=:org and type=:type" I have separate indexes on the User class. The first query will be fine, because of the Index on the foreign key element. Does the second query mandate a multi columnindex on org and type columns. If so how should I annotate to create one such index. @Entity class User { ...

How to create indexes on multiple columns

丶灬走出姿态 提交于 2020-02-15 13:47:54
问题 We have the following entity relationships where a User belongs to a particular Organization. My queries either look like "select * from User where org=:org" or "select * from User where org=:org and type=:type" I have separate indexes on the User class. The first query will be fine, because of the Index on the foreign key element. Does the second query mandate a multi columnindex on org and type columns. If so how should I annotate to create one such index. @Entity class User { ...