-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC 1024: Index ordering #83
Open
vpetrovykh
wants to merge
1
commit into
master
Choose a base branch
from
index_on
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
:: | ||
|
||
Status: Draft | ||
Type: Feature | ||
Created: 2023-08-09 | ||
Authors: Victor Petrovykh <[email protected]> | ||
|
||
======================== | ||
RFC 1024: Index Ordering | ||
======================== | ||
|
||
This RFC outlines an improvement to EdgeDB indexes that should make it easier | ||
for users to write queries that actually use the index speedups. | ||
|
||
|
||
Motivation | ||
========== | ||
|
||
In Postgres the indexes support "ordering" specificaion, so one can write: | ||
``CREATE INDEX test3_desc_index ON test3 (id DESC NULLS LAST);`` or ``CREATE | ||
INDEX test3_xy_index ON test3 (x ASC, y DESC);``. This allows fine-tuning | ||
indexes to the types of queries that you expect. We should replicate this | ||
capability in EdgeDB. | ||
|
||
|
||
Specification | ||
============= | ||
|
||
Instead of treating the ``on (...)`` clause as an expression, we can upgrade | ||
it to actually be an ordering clause for the index with syntax much like order | ||
by:: | ||
|
||
index on ( | ||
<expr> [ acs | desc ] [ empty { first | last } ] [ then ... ] | ||
) | ||
[ except ( <except-expr> ) ] | ||
[ "{" <annotation-declarations> "}" ] ; | ||
|
||
For example:: | ||
|
||
type Foo { | ||
text: str; | ||
x: int64; | ||
required y: int64; | ||
|
||
index on (.text asc empty last); | ||
index on (.x desc empty last then .y asc); | ||
} | ||
|
||
Notice that this approach works well with indexes that use more than one field | ||
and potentially need different ordering for different fields. | ||
|
||
Additionally, since this syntax naturally allows specifying several fields for | ||
indexing ``index on (.a then .b then .c)``, we no longer need to use a tuple | ||
expression to do that, removing the special case and making the index | ||
expression more semantically consistent. | ||
|
||
|
||
Implementation | ||
-------------- | ||
|
||
This change maps very naturally onto Postgres indexes. In particular, it | ||
removes the need to have a special case handling for tuples as index | ||
expression as we no longer need to use that format to create an index over | ||
multiple fields:: | ||
|
||
index on (.x desc empty last then .y asc); | ||
|
||
can be translated into:: | ||
|
||
CREATE INDEX foo_index ON "Foo" (x DESC NULLS LAST, y ASC); | ||
|
||
|
||
Backwards Compatibility | ||
======================= | ||
|
||
This change is *syntactically* backwards compatible since all of the extra | ||
specification for the index are optional. However, sematically, we should not | ||
interpret index on a tuple expression as index on several fields anymore. We | ||
should urge people to update their schemas to use this new version of index | ||
instead of a tuple expression. In theory this would involve a migration that | ||
only actually changes the schema text (and therefore the hash), but doesn't | ||
affect existing indexes. | ||
|
||
|
||
Security Implications | ||
===================== | ||
|
||
There are no security implications. | ||
|
||
|
||
Rejected Alternative Ideas | ||
========================== | ||
|
||
. . . |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think purity is worth the cost of breaking compatibility and requiring a migration. IMO we should continue to special-case tuples.