Repository navigation
Convert mz_index_columns to a builtin materialized view - #39427
SangJunBak merged 8 commits into
Conversation
a659af0 to
27c8872
Compare
27c8872 to
7857df2
Compare
7857df2 to
3a32217
Compare
3a32217 to
27a429d
Compare
27a429d to
3c03c63
Compare
2194479 to
ea159b9
Compare
38b4832 to
e10f1a1
Compare
df74254 to
89691b6
Compare
89691b6 to
b033e06
Compare
b033e06 to
ed0d814
Compare
QA LLM Review1. MEDIUM --
|
35f2e5a to
5035985
Compare
5035985 to
9cc5283
Compare
| JOIN mz_internal.mz_catalog_raw AS i ON | ||
| i.data->>'kind' = 'Item' AND | ||
| i.data->'key'->'gid' = k.data->'key'->'id' |
There was a problem hiding this comment.
This join arranges the full raw Item row of every item, create_sql included, keyed by gid (the Arrange (((#0{data} -> "key") -> "gid")) over Project: #0 in catalog_server_explain.slt). On a synthetic catalog with 14k items, that's about one copy of all create_sql text on mz_catalog_server (the mz_index_columns dataflow holds 53 MB there).
Only index items can match. Prefiltering them arranges only their rows. On that catalog, run as a user MV next to an exact copy of user_index_columns, the rows are identical and the size is 55 → 2.2 MB:
| JOIN mz_internal.mz_catalog_raw AS i ON | |
| i.data->>'kind' = 'Item' AND | |
| i.data->'key'->'gid' = k.data->'key'->'id' | |
| JOIN mz_internal.mz_catalog_raw AS i ON | |
| i.data->>'kind' = 'Item' AND | |
| i.data->'value'->'definition'->'V1'->>'create_sql' LIKE 'CREATE INDEX %' AND | |
| i.data->'key'->'gid' = k.data->'key'->'id' |
Every persisted index's create_sql starts with CREATE INDEX ", CREATE DEFAULT INDEX included, because planning fills in the name and key parts and drops IF NOT EXISTS.
parse_catalog_create_sql reports an index's key expressions in index order, so that mz_index_columns can read them.
The generated view lists the key columns of every builtin index, so that catalog views can reference them in SQL. To get information about a builtin index column, we parse the DDL of the builtin index to get information about the underlying relation, get the underlying relation's desc, then get the `on_position` and nullability from that. We also panic in this function if users ever create an expression for an index key.
- Deletes the builtin table packing code - Breaks GID_MAPPING_CTES into two CTEs such that we can reuse the builtin index CTE for mz_index_columns - Creates a definition for mz_index_columns using mz_catalog_raw and mz_builtin_index_columns - Creates a table to mv migration
Create an SLT to ensure: - The columns of the builtin report what we expect them to - We test for index keys that were created with expressions
The `IndexColumns` row of an index holds its key list, so the view unnests it with `WITH ORDINALITY`, whose one-based numbering is the reported index_position.
- Filters index_keys for just indexes so that the join arranges only their rows. It reduces the size from 55MB to 2.2 MB on a synthetic catalog with 14k items. - Also records the mz_index_columns conversion in the builtin version pin check.
From the durable index key information we recorded in #39818, we derive the index key information from it and convert mz_index_columns to a builtin mv.
See commit messages for more details
Motivation
Part of sql-494
Verification