diff --git a/e2e_test/batch/catalog/pg_indexes.slt.part b/e2e_test/batch/catalog/pg_indexes.slt.part index 634739406e91..c8e8ef626703 100644 --- a/e2e_test/batch/catalog/pg_indexes.slt.part +++ b/e2e_test/batch/catalog/pg_indexes.slt.part @@ -1,5 +1,5 @@ statement ok -create table t(a int, b int); +create table t(a int primary key, b int); statement ok create index idx1 on t(a); @@ -12,6 +12,7 @@ select schemaname, tablename, indexname, tablespace, indexdef from pg_catalog.pg ---- public t idx1 NULL CREATE INDEX idx1 ON t(a) public t idx2 NULL CREATE INDEX idx2 ON t(b) +public t t_pkey NULL (empty) statement ok drop table t; diff --git a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_index.rs b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_index.rs index b91bd9b698cb..f370b8615ad4 100644 --- a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_index.rs +++ b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_index.rs @@ -39,7 +39,34 @@ use risingwave_frontend_macro::system_catalog; true AS indisready, true AS indislive, false AS indisreplident - FROM rw_catalog.rw_indexes" + FROM rw_catalog.rw_indexes + UNION ALL + SELECT c.relation_id AS indexrelid, + c.relation_id AS indrelid, + COUNT(*)::smallint AS indnatts, + COUNT(*)::smallint AS indnkeyatts, + true AS indisunique, + ARRAY_AGG(c.position)::smallint[] AS indkey, + ARRAY[]::smallint[] as indoption, + NULL AS indexprs, + NULL AS indpred, + TRUE AS indisprimary, + ARRAY[]::int[] AS indclass, + false AS indisexclusion, + true AS indimmediate, + false AS indisclustered, + true AS indisvalid, + false AS indcheckxmin, + true AS indisready, + true AS indislive, + false AS indisreplident + FROM rw_catalog.rw_columns c + WHERE c.is_primary_key = true AND c.is_hidden = false + AND c.relation_id IN ( + SELECT id + FROM rw_catalog.rw_tables + ) + GROUP BY c.relation_id" )] #[derive(Fields)] struct PgIndex { diff --git a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_indexes.rs b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_indexes.rs index e35aba9567ae..a602e7180477 100644 --- a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_indexes.rs +++ b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_indexes.rs @@ -28,6 +28,19 @@ use risingwave_frontend_macro::system_catalog; FROM rw_catalog.rw_indexes i JOIN rw_catalog.rw_tables t ON i.primary_table_id = t.id JOIN rw_catalog.rw_schemas s ON i.schema_id = s.id + UNION ALL + SELECT s.name AS schemaname, + t.name AS tablename, + concat(t.name, '_pkey') AS indexname, + NULL AS tablespace, + '' AS indexdef + FROM rw_catalog.rw_tables t + JOIN rw_catalog.rw_schemas s ON t.schema_id = s.id + WHERE t.id IN ( + SELECT DISTINCT relation_id + FROM rw_catalog.rw_columns + WHERE is_primary_key = true AND is_hidden = false + ) " )] #[derive(Fields)]