Skip to content

Commit bf46d10

Browse files
committed
Added a long TODO note explaining buggy behavior for fresh servers
1 parent 75a258e commit bf46d10

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

testing/go/prepared_statement_test.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,13 +1334,35 @@ var pgCatalogTests = []ScriptTest{
13341334
},
13351335
},
13361336
{
1337-
Name: "pg_class",
1338-
Focus: true,
1337+
Name: "pg_class",
13391338
SetUpScript: []string{
13401339
`CREATE SCHEMA testschema;`,
13411340
`CREATE TABLE testschema.testtable (id int primary key, v1 text)`,
13421341
},
13431342
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+
},
13441366
{
13451367
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
13461368
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
13511373
},
13521374
{
13531375
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)
13551377
},
13561378
{
13571379
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

Comments
 (0)