Needed for #88061.
Describe the problem
CockroachDB does not include primary key columns in the indnkeyatts attribute of pg_index.
To Reproduce
Initialize with:
create table mytable(x int, y int);
Then use the following query (replace the 3 occurrences of XXXX by mytables' primary index OID):
WITH obj AS (
SELECT c.oid, c.relchecks, c.relkind, c.relhasindex, c.relhasrules,
c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity,
false AS relhasoids, c.relispartition, c.reltablespace,
CASE
WHEN c.reloftype = 0 THEN ''
ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END AS reloftype,
c.relpersistence, c.relreplident, am.amname
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)
LEFT JOIN pg_catalog.pg_am am ON (c.relam = am.oid)
WHERE c.oid = XXXXXXX), cols AS (
SELECT a.attname,
pg_catalog.format_type(a.atttypid, a.atttypmod) AS typname,
CASE WHEN a.attnum <= (
SELECT i.indnkeyatts
FROM pg_catalog.pg_index i
WHERE i.indexrelid = XXXXXXX) THEN 'yes' ELSE 'no' END AS is_key,
pg_catalog.pg_get_indexdef(a.attrelid, a.attnum, TRUE) AS indexdef
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = XXXXXXX AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum)
SELECT attname AS "Column",
typname AS "Type",
is_key AS "Key?",
indexdef AS "Definition"
FROM cols
(observe, the column rowid is not marked as Key because indnkeyatts is zero)
cc @rafiss for triage.
Jira issue: CRDB-19690
Epic: CRDB-23454
Needed for #88061.
Describe the problem
CockroachDB does not include primary key columns in the
indnkeyattsattribute ofpg_index.To Reproduce
Initialize with:
Then use the following query (replace the 3 occurrences of XXXX by mytables' primary index OID):
(observe, the column
rowidis not marked asKeybecauseindnkeyattsis zero)cc @rafiss for triage.
Jira issue: CRDB-19690
Epic: CRDB-23454