compound-index

MongoDB add fields of low cardinality to compound indexes?

你离开我真会死。 提交于 2021-01-28 02:51:19
问题 I have read putting indexes on low cardinality fields is pointless. Would this hold true for a compound index as such: db.perms.createIndex({"owner": 1, "object_type": 1, "target": 1}); With queries as such: db.perms.find({"owner": "me", "object_type": "square"}); db.perms.find({"owner": "me", "object_type": "circle", "target": "you"}); The amount of distinct object_type 's would grow over time (probably no more than 10 or 20 max) but would only start out with about 2 or 3. Similarly would a

Compound index with three keys, what happens if I query skipping the middle one?

和自甴很熟 提交于 2020-08-07 06:55:26
问题 With PostgreSQL, I want to use a compound index on three columns A, B, C . B is the created_at datetime, and occasionally I might query without B . What happens if I compound index on (A, B, C) but then query with conditions on A and C , but not B ? (That is, A and C but want it over all time, not just some specific time range?) Is Postgres smart enough to still use the (A, B, C) compound index but just skip B? 回答1: Postgres can use non-leading columns in a b-tree index, but in a far less

Compound index with three keys, what happens if I query skipping the middle one?

人走茶凉 提交于 2020-08-07 06:53:59
问题 With PostgreSQL, I want to use a compound index on three columns A, B, C . B is the created_at datetime, and occasionally I might query without B . What happens if I compound index on (A, B, C) but then query with conditions on A and C , but not B ? (That is, A and C but want it over all time, not just some specific time range?) Is Postgres smart enough to still use the (A, B, C) compound index but just skip B? 回答1: Postgres can use non-leading columns in a b-tree index, but in a far less

Mongodb compound indexes for filtering and sorting on BIG collection

∥☆過路亽.° 提交于 2019-12-25 01:11:01
问题 Can somebody tell me please if is possible to make indexes in Mongodb more efficient in this case: I have database with 50 millions items. There are two indexes on fields "ico" and "publishDate". Ico is used for filtering and publishDate for sorting . Is it possible to make it like a compound index to be more efficient? Can I combine filtering and sorting in compound index? Is important to choose which one should be the first in index definition? It is little complicated cause I have not the

IndexedDB IDBKeyRange Compound/Multiple Index not working

我们两清 提交于 2019-12-24 04:22:18
问题 Can anyone explain why my IDBKeyRange only seems to be filtering on the first column? I have an index defined as follows: osDrugs.createIndex("combined", ["name", "strength", "form", "packsize"], {unique: false}); My query is roughly as follows: var transaction = pimsDB.transaction("drugs"); var objectStore = transaction.objectStore("drugs"); var range = IDBKeyRange.bound([tmpName, tmpStrength, tmpForm, tmpPack],[tmpName+"z", tmpStrength + "z", tmpForm+"z", tmpPack+"z"]); var index =

Optimization of query using covering indices

一个人想着一个人 提交于 2019-12-13 05:55:13
问题 I have the following query with a subquery and self join: SELECT bucket.patient_sid AS sid FROM (SELECT clinical_data.patient_sid, clinical_data.lft, clinical_data.rgt FROM clinical_data INNER JOIN (SELECT clinical_data.patient_sid, clinical_data.lft, clinical_data.rgt, clinical_data.attribute_id FROM clinical_data WHERE clinical_data.attribute_id = '33' AND clinical_data.string_value = '2160-0') AS attribute ON clinical_data.patient_sid = attribute.patient_sid AND clinical_data.lft >=

MongoDB Compound Indexes - Does the sort order matter?

江枫思渺然 提交于 2019-12-12 09:27:32
问题 I've dived recently into mongodb for a project of mine. I've been reading up on indexes, and for a small collection, i know it wouldn't matter much but when it grows there's going to be performance issues without the right indexes and queries. Lets say i have a collection like so {user_id:1,slug:'one-slug'} {user_id:1,slug:'another-slug'} {user_id:2,slug:'one-slug'} {user_id:3,slug:'just-a-slug} And i have to search my collection where user id == 1 and slug == 'one-slug' In this collection,

MongoDB not using my index

心已入冬 提交于 2019-12-11 17:37:01
问题 I have a logs collection with millions of records. Creating a new index takes "forever". So it would be preferred to use existing indexes. Now I want to get the number of occurances of certain error codes. I use this query, and functionally it works fine: db.getCollection('logs.res').aggregate([ { $match:{ timeStamp: { $gte: new Date('2017-05-01').getTime(), // timeStamp is Number $lt : new Date('2017-05-02').getTime() // of ms since epoch }, 'objData.@.ErrorCode': { $ne: null } } }, { $group

How to find documents having a query-value within the range of two key-values

走远了吗. 提交于 2019-12-11 13:39:21
问题 I'm analyzing texts. Those texts have annotations (e.g. "chapter", "scenery", ...). Those annotations are in my MongoDB collection annotations , e.g. { start: 1, stop: 10000, type: chapter, details: { number: 1, title: "Where it all began" } }, { start: 10001, stop: 20000, type: chapter, details: { number: 2, title: "Lovers" } }, { start: 1, stop: 5000, type: scenery, details: { descr: "castle" } }, { start: 5001, stop: 15000, type: scenery, details: { descr: "forest" } } Challenge 1 : For a

MongoDB compound sparse indexes

拥有回忆 提交于 2019-12-11 06:19:29
问题 I have a followig compound index: db.nodes.createIndex( { parent: 1, name: 1 }, { unique: true } ); that index forbides to insert two docs with same name and parent for example: var n=db.nodes; n.insert({parent:0,name:"node"}); n.insert({parent:0,name:"node1"}); n.insert({parent:0,name:"node2"}); n.insert({parent:0,name:"node3"}); //throws an error because of compound index: n.insert({parent:0,name:"node"}); that is ok. Now if name is null (or not present) i want to add multiple docs with