[SERVER-14784] Add expression indexes Created: 04/Aug/14  Updated: 05/Dec/22

Status: Backlog
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Scott Hernandez (Inactive) Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 18
Labels: product-priority
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
is related to SERVER-153 javascript sort helper for custom sor... Backlog
is related to SERVER-3260 Prefix Indexes Backlog
is related to SERVER-90 case insensitive index Closed
Assigned Teams:
Query Execution
Backwards Compatibility: Major Change
Participants:
Case:

 Description   

An expression index is one where the value being indexed is the result of an expression, like lower casing a string.

http://en.wikipedia.org/wiki/Expression_index
http://www.postgresql.org/docs/8.1/static/indexes-expressional.html

One possible way of specifying the expression could be through the existing aggregation expressions: http://docs.mongodb.org/manual/reference/operator/aggregation/#arithmetic-operators

db.coll.addIndex("lowercase_name", {$expression: {$toLower:"$name"}});

Note: In the example above there is no name for the expression, aside from the index name, because any name could conflict with documents. Also, the expression should be used in the query; the query expression may be a sub/superset of the index expression, or multiple indexes.

Any expression support in indexes requires those expressions be available in the query language as well; it could look like this:

db.coll.find({$expression: {$eq:["scott", {$toLower:"$name"}]}})



 Comments   
Comment by Oliver Reid [ 06/Nov/22 ]

It would be even more helpful if the value of the expression cold be added as user_named document field - like a stored virtual field in MySQl

Generated at Thu Feb 08 03:35:59 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.