Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose PK info in index system catalog #17262

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion e2e_test/batch/catalog/pg_indexes.slt.part
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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;
29 changes: 28 additions & 1 deletion src/frontend/src/catalog/system_catalog/pg_catalog/pg_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions src/frontend/src/catalog/system_catalog/pg_catalog/pg_indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Loading