Repository navigation
dialect, metadata: descending index columns - #91
Merged
Merged
Conversation
An index column that sorts descending could not be written, as the dialect API had no ASC or DESC for an index column, and four providers read the order wrongly or not at all. DdlGenerator gains the records IndexColumn(name, descending) and IndexDefinition(name, table, columns, unique, condition), createIndex(IndexDefinition, ifNotExists), which writes DESC after a descending column and the condition of a partial index, and supportsDescendingIndexColumns(), false by default. An index of ascending columns is the plain index of every dialect; a descending column is empty where the database keeps no order. PostgreSQL, Oracle, SQL Server, H2, SQLite and Derby keep it, MySQL from 8.0 and MariaDB from 10.8; before, both took DESC and ignored it. DuckDB takes DESC and drops it, and ClickHouse, Hive, Impala and the ANSI dialect have no such index. The providers now read the order: - Oracle keeps a descending column as a function-based column with a system name, SYS_NC00005$, and reported that name. It now reads the column from ALL_IND_EXPRESSIONS where the expression is a plain column. - MySQL and MariaDB read it from information_schema.STATISTICS COLLATION, A or D, and none where the index keeps no order. - H2 reads INDEX_COLUMNS.ORDERING_SPECIFICATION. PostgreSQL and SQL Server read it already. The consistency tests check the statements of every dialect. On PostgreSQL, SQL Server, Oracle, MySQL and MariaDB an index with a descending column is created, read back by the provider with the order of each column and dropped; on SQLite the order is read from the index itself. The metadata contract creates such an index on every database and expects each column's order back, except on DuckDB. Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
An index column that sorts descending could not be written, as the dialect API had no
ASCorDESCfor an index column, and four providers read the order wrongly or not at all.What changes
DdlGeneratorgains:IndexColumn(name, descending)andIndexDefinition(name, table, columns, unique, condition)Optional<String> createIndex(IndexDefinition index, boolean ifNotExists), which writesDESCafter a descending column and the condition of a partial indexboolean supportsDescendingIndexColumns(), false by defaultAn index of ascending columns is the plain index of every dialect; a descending column is empty where the database keeps no order.
DESCand ignored itDESCand drops itThe providers now read the order:
SYS_NC00005$) and reported that name. It now reads the column fromALL_IND_EXPRESSIONSwhere the expression is a plain column.information_schema.STATISTICS.COLLATION(AorD), and none where the index keeps no order.INDEX_COLUMNS.ORDERING_SPECIFICATION.PostgreSQL and SQL Server read it already.
Tests
The consistency tests check the statements of every dialect. On PostgreSQL, SQL Server, Oracle, MySQL and MariaDB an index with a descending column is created, read back by the provider with the order of each column and dropped; on SQLite the order is read from the index itself. The metadata contract creates such an index on every database and expects each column's order back, except on DuckDB.