yugabyte / yugabyte-db

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.
https://www.yugabyte.com
Other
8.65k stars 1.04k forks source link

[YSQL] JDBC DatabaseMetadata implementation incorrectly classifies HASH index columns with ASC sort order #23112

Open markallanson opened 2 days ago

markallanson commented 2 days ago

Jira Link: DB-12045

Description

JDBC API states that getIndexInfo should return null as the sort order when a column does not contribute to sort.

ASC_OR_DESC String => column sort sequence, "A" => ascending, "D" => descending, may be null if sort sequence is not supported; null when TYPE is tableIndexStatistic

For columns that are hashed in indexes, the Yugabyte PGJDBC driver incorrectly returns A - Ascending order, instead of setting the value to null.

The code in question that is the source of this bug is: https://github.com/yugabyte/pgjdbc/blob/d04fc3c064be3b69969b3cb5f72ee59e9c5d2279/pgjdbc/src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java#L2558

Issue Type

kind/bug

Warning: Please confirm that this issue does not contain any sensitive information

FranckPachot commented 2 days ago

The code you pointed at should return NULL when AM_NAME is not 'btree' and YugabyteDB tables are 'lsm' Can you check the index definition for the one that returns bad index info

select distinct am.amname AS AM_NAME , pg_get_indexdef(i.indexrelid)
            FROM pg_catalog.pg_class ct
              JOIN pg_catalog.pg_namespace n ON (ct.relnamespace = n.oid)
              JOIN pg_catalog.pg_index i ON (ct.oid = i.indrelid)
              JOIN pg_catalog.pg_class ci ON (ci.oid = i.indexrelid)
              JOIN pg_catalog.pg_am am ON (ci.relam = am.oid)
where ci.relname like '%%'
;