-
Notifications
You must be signed in to change notification settings - Fork 73
DOC Document default_sort composite indexes #755
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
DOC Document default_sort composite indexes #755
Conversation
| this index is present on the associative entity). | ||
| - All fields used in `default_sort` configuration | ||
| - All fields used in `default_sort` configuration (see [`default_sort` index mode](#default-sort-index-mode) below for additional options) | ||
| - Some built-in models (such as [`Member`](api:SilverStripe\Security\Member)) have specific indexes added |
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.
Added this last note for completion's sake
| class MyObject extends DataObject | ||
| { | ||
| private static $indexes = [ | ||
| private static array $indexes = [ |
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.
Unrelated - just updating the config references in this page to follow latest best practice
| ``` | ||
|
|
||
| ## Complex/Composite indexes | ||
| ### Complex/Composite indexes |
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.
Makes sense as a subheading of "Defining an index"
| - index (col1) - `WHERE col1 = ?` | ||
| - index (col1, col2) = `WHERE (col1 = ? AND col2 = ?)` | ||
| - index (col1, col2, col3) = `WHERE (col1 = ? AND col2 = ? AND col3 = ?)` | ||
| ```php | ||
| namespace App\Model; | ||
|
|
||
| The index would not be used for a query `WHERE col2 = ?` or for `WHERE col1 = ? OR col2 = ?` | ||
| use SilverStripe\ORM\DataObject; | ||
|
|
||
| class MyTestObject extends DataObject | ||
| { | ||
| // ... | ||
| private static array $indexes = [ | ||
| 'MyCompositeIndex' => ['MyField', 'MyOtherField', 'MyThirdField'], | ||
| ]; | ||
| } | ||
| ``` | ||
|
|
||
| Composite indexes can be used for any query that uses the fields in this specific order, include queries that omit columns from later in the index. For example, the index would be used for these queries: | ||
|
|
||
| - `WHERE MyField = ?` | ||
| - `WHERE (MyField = ? AND MyOtherField = ?)` | ||
| - `WHERE (MyField = ? AND MyOtherField = ? AND MyThirdField = ?)` | ||
|
|
||
| The index would not be used for a query `WHERE MyOtherField = ?` (because the first column is not used in this query) or for `WHERE MyField = ? OR MyOtherField = ?` (because the database has to check all rows to see if the `MyOtherField` column matches on its own). |
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.
Updated this to be clearer - it wasn't really obvious what index (col1, col2) meant - was that a separate index or just showing that only col1 and col2 of the 3-column index were being used?
emteknetnz
left a comment
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.
Merge conflict
cf37906 to
ef8177c
Compare
|
Conflict resolved |
ef8177c to
d54bab7
Compare
…efault-sort-index DOC Document default_sort composite indexes
…efault-sort-index DOC Document default_sort composite indexes
Issue
default_sortwith multiple columns silverstripe-framework#11674