You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: testing/go/prepared_statement_test.go
+25-3Lines changed: 25 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1334,13 +1334,35 @@ var pgCatalogTests = []ScriptTest{
1334
1334
},
1335
1335
},
1336
1336
{
1337
-
Name: "pg_class",
1338
-
Focus: true,
1337
+
Name: "pg_class",
1339
1338
SetUpScript: []string{
1340
1339
`CREATE SCHEMA testschema;`,
1341
1340
`CREATE TABLE testschema.testtable (id int primary key, v1 text)`,
1342
1341
},
1343
1342
Assertions: []ScriptTestAssertion{
1343
+
{
1344
+
Query: "select distinct relnamespace from pg_catalog.pg_class c INNER JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname=$1;",
1345
+
BindVars: []any{"testschema"},
1346
+
Expected: []sql.Row{{2638679668}},
1347
+
},
1348
+
// TODO: when this test is run in isolation without the query above, the below query returns no rows. This is
1349
+
// because the process of converting an OID to its internal ID can only proceed in one direction: from internal
1350
+
// to OID. When the above query runs, it causes the internal ID for the testschema namespace to be cached,
1351
+
// allowing the reverse lookup to succeed in subsequent queries. For OIDs that have not yet been cached in this
1352
+
// manner, lookups by their OID will fail. This doesn't impact all queries since many of them get an index
1353
+
// lookup on OID, which has the side effect of converting everything to numeric IDs anyway. But for queries
1354
+
// that use a normal comparison function for an OID literal value, the conversion to an internal ID of the
1355
+
// appropriate type (e.g. id.Namespace) cannot happen in the |oidin| function in some cases because the internal
1356
+
// to OID mapping hasn't yet been established for that schema element, so the comparison fails, yielding
1357
+
// incorrect results.
1358
+
// To fix this, we need to correctly seed the internal ID cache with all schema elements in the database.
1359
+
{
1360
+
Query: `SELECT c.oid,pg_catalog.pg_get_expr(c.relpartbound, c.oid) as partition_expr, pg_catalog.pg_get_partkeydef(c.oid) as partition_key
1361
+
FROM pg_catalog.pg_class c
1362
+
WHERE c.relnamespace=$1 AND c.relkind not in ('i','I','c') and c.oid not in (select oid from pg_catalog.pg_class where left(relname, 5) = 'dolt_');`,
1363
+
BindVars: []any{2638679668},
1364
+
Expected: []sql.Row{{1712283605, nil, ""}},
1365
+
},
1344
1366
{
1345
1367
Query: `SELECT c.oid,d.description,pg_catalog.pg_get_expr(c.relpartbound, c.oid) as partition_expr, pg_catalog.pg_get_partkeydef(c.oid) as partition_key
1346
1368
FROM pg_catalog.pg_class c
@@ -1351,7 +1373,7 @@ WHERE c.relnamespace=$1 AND c.relkind not in ('i','I','c') and c.oid not in (sel
1351
1373
},
1352
1374
{
1353
1375
Query: `SELECT d.description from pg_catalog.pg_description d WHERE d.classoid='pg_class'::regclass`,
1354
-
// TODO: add expected values
1376
+
// TODO: add expected values (pg_description not yet implemented)
1355
1377
},
1356
1378
{
1357
1379
Query: `select c.oid,pg_catalog.pg_total_relation_size(c.oid) as total_rel_size,pg_catalog.pg_relation_size(c.oid) as rel_size FROM pg_class c WHERE c.relnamespace=$1 and c.oid not in (select oid from pg_catalog.pg_class where left(relname, 5) = 'dolt_');`,
0 commit comments