Skip to content

Commit

Permalink
refactor(frontend): manually implement reader for pg_type to ensure…
Browse files Browse the repository at this point in the history
… `oid` is the primary key (#15290)

Signed-off-by: Bugen Zhao <[email protected]>
  • Loading branch information
BugenZhao authored Feb 28, 2024
1 parent 93a283a commit 495ed83
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 63 deletions.
46 changes: 46 additions & 0 deletions e2e_test/batch/catalog/atlasgo.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,52 @@ ORDER BY
n.nspname, e.enumtypid, e.enumsortorder
----

query T rowsort
SELECT
(
SELECT
t.typtype
FROM
pg_catalog.pg_type AS t
WHERE
t.oid = t4.typelem
) AS elemtyp
FROM
pg_catalog.pg_type AS t4;
----
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
b
b
b
b
b
b
b
b
b
b
b
b
b
b
b

query TTTTTTTTTTTTTTTTTTTTTT
SELECT
t1.table_name,
Expand Down
14 changes: 14 additions & 0 deletions src/frontend/planner_test/tests/testdata/input/atlasgo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- sql: |
SELECT
(
SELECT
t.typtype
FROM
pg_catalog.pg_type AS t
WHERE
t.oid = t4.typelem
) AS elemtyp
FROM
pg_catalog.pg_type AS t4;
expected_outputs:
- batch_plan
21 changes: 21 additions & 0 deletions src/frontend/planner_test/tests/testdata/output/atlasgo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is automatically generated. See `src/frontend/planner_test/README.md` for more information.
- sql: |
SELECT
(
SELECT
t.typtype
FROM
pg_catalog.pg_type AS t
WHERE
t.oid = t4.typelem
) AS elemtyp
FROM
pg_catalog.pg_type AS t4;
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchHashJoin { type: LeftOuter, predicate: pg_type.typelem = pg_type.oid, output: [pg_type.typtype] }
├─BatchExchange { order: [], dist: HashShard(pg_type.typelem) }
│ └─BatchScan { table: pg_type, columns: [pg_type.typelem], distribution: Single }
└─BatchExchange { order: [], dist: HashShard(pg_type.oid) }
└─BatchProject { exprs: [pg_type.typtype, pg_type.oid] }
└─BatchScan { table: pg_type, columns: [pg_type.oid, pg_type.typtype], distribution: Single }
26 changes: 11 additions & 15 deletions src/frontend/planner_test/tests/testdata/output/dbeaver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,28 @@
└─BatchSort { order: [$expr4 ASC] }
└─BatchHashAgg { group_key: [null:Varchar, null:Int32, null:Int32, $expr1, rw_columns.name, '':Varchar, $expr4, $expr5, $expr6, $expr7], aggs: [] }
└─BatchExchange { order: [], dist: HashShard(null:Varchar, null:Int32, null:Int32, $expr1, rw_columns.name, '':Varchar, $expr4, $expr5, $expr6, $expr7) }
└─BatchProject { exprs: [null:Varchar, null:Int32, null:Int32, $expr1, rw_columns.name, '':Varchar, Case(IsNotNull($expr1), ConcatOp($expr1, Coalesce(null:Int16::Varchar, '':Varchar)), IsNotNull(null:Int32), 'T':Varchar, IsNotNull(rw_types.id), 'y':Varchar, IsNotNull(rw_schemas.id), 'n':Varchar, IsNotNull(null:Int32), 'p':Varchar, IsNotNull(null:Int32), 'l':Varchar, IsNotNull(null:Int32), 'R':Varchar, IsNotNull(pg_constraint.oid), ConcatOp('C':Varchar, pg_constraint.contype), IsNotNull(null:Int32), 'A':Varchar, '':Varchar) as $expr4, Coalesce(rw_tables.name, rw_tables.name, rw_tables.name) as $expr5, Case((IsNotNull(rw_tables.name) AND IsNotNull(rw_columns.name)), ConcatOp(ConcatOp(rw_tables.name, '.':Varchar), rw_columns.name), Coalesce(rw_tables.name, pg_constraint.conname, null:Varchar, null:Varchar, rw_types.name, null:Varchar, null:Varchar, rw_schemas.name)) as $expr6, Coalesce(rw_schemas.name, rw_schemas.name, rw_schemas.name, rw_schemas.name, rw_schemas.name, rw_schemas.name) as $expr7] }
└─BatchHashJoin { type: LeftOuter, predicate: null:Int32 = rw_columns.relation_id AND null:Int16 = $expr3, output: [null:Int32, null:Int32, null:Int16, null:Varchar, rw_tables.name, $expr1, rw_columns.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name, rw_types.id, rw_types.name, rw_schemas.name, pg_constraint.oid, pg_constraint.conname, pg_constraint.contype, rw_tables.name, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.id, rw_schemas.name, null:Int32, rw_columns.name] }
└─BatchProject { exprs: [null:Varchar, null:Int32, null:Int32, $expr1, rw_columns.name, '':Varchar, Case(IsNotNull($expr1), ConcatOp($expr1, Coalesce(null:Int16::Varchar, '':Varchar)), IsNotNull(null:Int32), 'T':Varchar, IsNotNull(pg_type.oid), 'y':Varchar, IsNotNull(rw_schemas.id), 'n':Varchar, IsNotNull(null:Int32), 'p':Varchar, IsNotNull(null:Int32), 'l':Varchar, IsNotNull(null:Int32), 'R':Varchar, IsNotNull(pg_constraint.oid), ConcatOp('C':Varchar, pg_constraint.contype), IsNotNull(null:Int32), 'A':Varchar, '':Varchar) as $expr4, Coalesce(rw_tables.name, rw_tables.name, rw_tables.name) as $expr5, Case((IsNotNull(rw_tables.name) AND IsNotNull(rw_columns.name)), ConcatOp(ConcatOp(rw_tables.name, '.':Varchar), rw_columns.name), Coalesce(rw_tables.name, pg_constraint.conname, null:Varchar, null:Varchar, pg_type.typname, null:Varchar, null:Varchar, rw_schemas.name)) as $expr6, Coalesce(rw_schemas.name, rw_schemas.name, rw_schemas.name, rw_schemas.name, rw_schemas.name, rw_schemas.name) as $expr7] }
└─BatchHashJoin { type: LeftOuter, predicate: null:Int32 = rw_columns.relation_id AND null:Int16 = $expr3, output: [null:Int32, null:Int32, null:Int16, null:Varchar, rw_tables.name, $expr1, rw_columns.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name, pg_type.oid, pg_type.typname, rw_schemas.name, pg_constraint.oid, pg_constraint.conname, pg_constraint.contype, rw_tables.name, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.id, rw_schemas.name, null:Int32, rw_columns.name] }
├─BatchExchange { order: [], dist: HashShard(null:Int32, null:Int16) }
│ └─BatchHashJoin { type: LeftOuter, predicate: null:Int32 = null:Int32, output: all }
│ ├─BatchHashJoin { type: LeftOuter, predicate: null:Int32 = rw_schemas.id, output: all }
│ │ ├─BatchHashJoin { type: LeftOuter, predicate: null:Int32 = null:Int32, output: all }
│ │ │ ├─BatchExchange { order: [], dist: HashShard(null:Int32) }
│ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: rw_tables.schema_id = rw_schemas.id, output: [null:Int32, null:Int32, null:Int16, null:Varchar, rw_tables.name, $expr1, rw_columns.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name, rw_types.id, rw_types.name, rw_schemas.name, pg_constraint.oid, pg_constraint.conname, pg_constraint.contype, rw_tables.name, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name] }
│ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: rw_tables.schema_id = rw_schemas.id, output: [null:Int32, null:Int32, null:Int16, null:Varchar, rw_tables.name, $expr1, rw_columns.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name, pg_type.oid, pg_type.typname, rw_schemas.name, pg_constraint.oid, pg_constraint.conname, pg_constraint.contype, rw_tables.name, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name] }
│ │ │ │ ├─BatchExchange { order: [], dist: HashShard(rw_tables.schema_id) }
│ │ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: null:Int32 = rw_tables.id, output: [null:Int32, null:Int32, null:Int16, null:Varchar, rw_tables.name, $expr1, rw_columns.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name, rw_types.id, rw_types.name, rw_schemas.name, pg_constraint.oid, pg_constraint.conname, pg_constraint.contype, rw_tables.name, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_tables.schema_id] }
│ │ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: null:Int32 = rw_tables.id, output: [null:Int32, null:Int32, null:Int16, null:Varchar, rw_tables.name, $expr1, rw_columns.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name, pg_type.oid, pg_type.typname, rw_schemas.name, pg_constraint.oid, pg_constraint.conname, pg_constraint.contype, rw_tables.name, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_tables.schema_id] }
│ │ │ │ │ ├─BatchExchange { order: [], dist: HashShard(null:Int32) }
│ │ │ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: null:Int32 = null:Int32, output: all }
│ │ │ │ │ │ ├─BatchExchange { order: [], dist: HashShard(null:Int32) }
│ │ │ │ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: pg_constraint.connamespace = rw_schemas.id, output: [null:Int32, null:Int32, null:Int16, null:Varchar, rw_tables.name, $expr1, rw_columns.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name, rw_types.id, rw_types.name, rw_schemas.name, pg_constraint.oid, pg_constraint.conname, pg_constraint.contype, rw_tables.name, rw_schemas.name] }
│ │ │ │ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: pg_constraint.connamespace = rw_schemas.id, output: [null:Int32, null:Int32, null:Int16, null:Varchar, rw_tables.name, $expr1, rw_columns.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name, pg_type.oid, pg_type.typname, rw_schemas.name, pg_constraint.oid, pg_constraint.conname, pg_constraint.contype, rw_tables.name, rw_schemas.name] }
│ │ │ │ │ │ │ ├─BatchExchange { order: [], dist: HashShard(pg_constraint.connamespace) }
│ │ │ │ │ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: pg_constraint.conrelid = rw_tables.id, output: [null:Int32, null:Int32, null:Int16, null:Varchar, rw_tables.name, $expr1, rw_columns.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name, rw_types.id, rw_types.name, rw_schemas.name, pg_constraint.oid, pg_constraint.conname, pg_constraint.connamespace, pg_constraint.contype, rw_tables.name] }
│ │ │ │ │ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: pg_constraint.conrelid = rw_tables.id, output: [null:Int32, null:Int32, null:Int16, null:Varchar, rw_tables.name, $expr1, rw_columns.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name, pg_type.oid, pg_type.typname, rw_schemas.name, pg_constraint.oid, pg_constraint.conname, pg_constraint.connamespace, pg_constraint.contype, rw_tables.name] }
│ │ │ │ │ │ │ │ ├─BatchExchange { order: [], dist: HashShard(pg_constraint.conrelid) }
│ │ │ │ │ │ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: null:Int32 = pg_constraint.oid, output: all }
│ │ │ │ │ │ │ │ │ ├─BatchExchange { order: [], dist: HashShard(null:Int32) }
│ │ │ │ │ │ │ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: rw_schemas.id = rw_schemas.id, output: [null:Int32, null:Int32, null:Int16, null:Varchar, rw_tables.name, $expr1, rw_columns.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name, rw_types.id, rw_types.name, rw_schemas.name] }
│ │ │ │ │ │ │ │ │ │ ├─BatchExchange { order: [], dist: HashShard(rw_schemas.id) }
│ │ │ │ │ │ │ │ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: null:Int32 = rw_types.id, output: all }
│ │ │ │ │ │ │ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: pg_type.typnamespace = rw_schemas.id, output: [null:Int32, null:Int32, null:Int16, null:Varchar, rw_tables.name, $expr1, rw_columns.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name, pg_type.oid, pg_type.typname, rw_schemas.name] }
│ │ │ │ │ │ │ │ │ │ ├─BatchExchange { order: [], dist: HashShard(pg_type.typnamespace) }
│ │ │ │ │ │ │ │ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: null:Int32 = pg_type.oid, output: all }
│ │ │ │ │ │ │ │ │ │ │ ├─BatchExchange { order: [], dist: HashShard(null:Int32) }
│ │ │ │ │ │ │ │ │ │ │ │ └─BatchHashJoin { type: LeftOuter, predicate: rw_tables.schema_id = rw_schemas.id, output: [null:Int32, null:Int32, null:Int16, null:Varchar, rw_tables.name, $expr1, rw_columns.name, rw_schemas.name, null:Int32, null:Varchar, rw_schemas.name, null:Int32, null:Varchar, rw_tables.name, rw_schemas.name] }
│ │ │ │ │ │ │ │ │ │ │ │ ├─BatchExchange { order: [], dist: HashShard(rw_tables.schema_id) }
Expand Down Expand Up @@ -125,12 +125,8 @@
│ │ │ │ │ │ │ │ │ │ │ │ │ └─BatchScan { table: rw_views, columns: [rw_views.id, rw_views.name, rw_views.schema_id], distribution: Single }
│ │ │ │ │ │ │ │ │ │ │ │ └─BatchExchange { order: [], dist: HashShard(rw_schemas.id) }
│ │ │ │ │ │ │ │ │ │ │ │ └─BatchScan { table: rw_schemas, columns: [rw_schemas.id, rw_schemas.name], distribution: Single }
│ │ │ │ │ │ │ │ │ │ │ └─BatchExchange { order: [], dist: HashShard(rw_types.id) }
│ │ │ │ │ │ │ │ │ │ │ └─BatchNestedLoopJoin { type: Inner, predicate: true, output: all }
│ │ │ │ │ │ │ │ │ │ │ ├─BatchScan { table: rw_types, columns: [rw_types.id, rw_types.name], distribution: Single }
│ │ │ │ │ │ │ │ │ │ │ └─BatchProject { exprs: [rw_schemas.id] }
│ │ │ │ │ │ │ │ │ │ │ └─BatchFilter { predicate: (rw_schemas.name = 'pg_catalog':Varchar) }
│ │ │ │ │ │ │ │ │ │ │ └─BatchScan { table: rw_schemas, columns: [rw_schemas.id, rw_schemas.name], distribution: Single }
│ │ │ │ │ │ │ │ │ │ │ └─BatchExchange { order: [], dist: HashShard(pg_type.oid) }
│ │ │ │ │ │ │ │ │ │ │ └─BatchScan { table: pg_type, columns: [pg_type.oid, pg_type.typname, pg_type.typnamespace], distribution: Single }
│ │ │ │ │ │ │ │ │ │ └─BatchExchange { order: [], dist: HashShard(rw_schemas.id) }
│ │ │ │ │ │ │ │ │ │ └─BatchScan { table: rw_schemas, columns: [rw_schemas.id, rw_schemas.name], distribution: Single }
│ │ │ │ │ │ │ │ │ └─BatchExchange { order: [], dist: HashShard(pg_constraint.oid) }
Expand Down
16 changes: 3 additions & 13 deletions src/frontend/planner_test/tests/testdata/output/pg_catalog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@
- sql: |
select * from pg_catalog.pg_type
logical_plan: |-
LogicalProject { exprs: [rw_types.id, rw_types.name, rw_types.typelem, rw_types.typarray, rw_types.input_oid, false:Boolean, 0:Int32, -1:Int32, 0:Int32, 0:Int32, rw_schemas.id, 'b':Varchar, 0:Int32, null:Varchar, null:Varchar, null:Int32] }
└─LogicalShare { id: 3 }
└─LogicalProject { exprs: [rw_types.id, rw_types.name, rw_types.typelem, rw_types.typarray, rw_types.input_oid, false:Boolean, 0:Int32, -1:Int32, 0:Int32, 0:Int32, rw_schemas.id, 'b':Varchar, 0:Int32, null:Varchar, null:Varchar, null:Int32] }
└─LogicalJoin { type: Inner, on: (rw_schemas.name = 'pg_catalog':Varchar), output: all }
├─LogicalSysScan { table: rw_types, columns: [rw_types.id, rw_types.name, rw_types.input_oid, rw_types.typelem, rw_types.typarray] }
└─LogicalSysScan { table: rw_schemas, columns: [rw_schemas.id, rw_schemas.name, rw_schemas.owner, rw_schemas.acl] }
batch_plan: |-
BatchProject { exprs: [rw_types.id, rw_types.name, rw_types.typelem, rw_types.typarray, rw_types.input_oid, false:Boolean, 0:Int32, -1:Int32, 0:Int32, 0:Int32, rw_schemas.id, 'b':Varchar, 0:Int32, null:Varchar, null:Varchar, null:Int32] }
└─BatchNestedLoopJoin { type: Inner, predicate: true, output: all }
├─BatchScan { table: rw_types, columns: [rw_types.id, rw_types.name, rw_types.input_oid, rw_types.typelem, rw_types.typarray], distribution: Single }
└─BatchProject { exprs: [rw_schemas.id] }
└─BatchFilter { predicate: (rw_schemas.name = 'pg_catalog':Varchar) }
└─BatchScan { table: rw_schemas, columns: [rw_schemas.id, rw_schemas.name], distribution: Single }
LogicalProject { exprs: [pg_type.oid, pg_type.typname, pg_type.typelem, pg_type.typarray, pg_type.typinput, pg_type.typnotnull, pg_type.typbasetype, pg_type.typtypmod, pg_type.typcollation, pg_type.typlen, pg_type.typnamespace, pg_type.typtype, pg_type.typrelid, pg_type.typdefault, pg_type.typcategory, pg_type.typreceive] }
└─LogicalSysScan { table: pg_type, columns: [pg_type.oid, pg_type.typname, pg_type.typelem, pg_type.typarray, pg_type.typinput, pg_type.typnotnull, pg_type.typbasetype, pg_type.typtypmod, pg_type.typcollation, pg_type.typlen, pg_type.typnamespace, pg_type.typtype, pg_type.typrelid, pg_type.typdefault, pg_type.typcategory, pg_type.typreceive] }
batch_plan: 'BatchScan { table: pg_type, columns: [pg_type.oid, pg_type.typname, pg_type.typelem, pg_type.typarray, pg_type.typinput, pg_type.typnotnull, pg_type.typbasetype, pg_type.typtypmod, pg_type.typcollation, pg_type.typlen, pg_type.typnamespace, pg_type.typtype, pg_type.typrelid, pg_type.typdefault, pg_type.typcategory, pg_type.typreceive], distribution: Single }'
- sql: |
select * from pg_catalog.pg_namespace
logical_plan: |-
Expand Down
Loading

0 comments on commit 495ed83

Please sign in to comment.