Skip to content

dialect, metadata: descending index columns - #91

Merged
stbischof merged 1 commit into
mainfrom
feature/descending-index-columns
Nov 11, 2026
Merged

stbischof merged 1 commit into
mainfrom
feature/descending-index-columns

Conversation

@stbischof

Copy link
Copy Markdown
Contributor

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.

What changes

DdlGenerator gains:

  • the records IndexColumn(name, descending) and IndexDefinition(name, table, columns, unique, condition)
  • Optional<String> createIndex(IndexDefinition index, boolean ifNotExists), which writes DESC after a descending column and the condition of a partial index
  • boolean 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.

Dialect Descending index column
PostgreSQL, Oracle, SQL Server, H2, SQLite, Derby kept
MySQL from 8.0, MariaDB from 10.8 kept; before, both took DESC and ignored it
DuckDB none: it takes DESC and drops it
ClickHouse, Hive, Impala, ANSI 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.

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.

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>
@stbischof
stbischof merged commit b2e7592 into main Nov 11, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant