@@ -346,19 +346,33 @@ func TestCTIDPartitioningOnPartitionedTable(t *testing.T) {
346346
347347func TestCTIDPartitioningOnMultiLevelPartitionedTable (t * testing.T ) {
348348 t .Parallel ()
349- schemaName , conn , connStr := setupTestSchema (t )
349+ _ , conn , connStr := setupTestSchema (t )
350350
351- // Root table partitioned by region
352- rootTable := schemaName + ".multi_level"
353- _ , err := conn .Exec (t .Context (), fmt .Sprintf (`
351+ // Use a mixed-case schema name as well to verify OID-based lookups work
352+ // for both schema and table identifiers (to_regclass lowercases unquoted identifiers).
353+ schemaName := "Test_" + shared .RandomString (8 )
354+ schemaNameDDL := `"` + schemaName + `"`
355+ _ , err := conn .Exec (t .Context (), `CREATE SCHEMA ` + schemaNameDDL )
356+ require .NoError (t , err )
357+ t .Cleanup (func () {
358+ if _ , err := conn .Exec (t .Context (), `DROP SCHEMA ` + schemaNameDDL + ` CASCADE` ); err != nil {
359+ t .Logf ("Failed to drop schema: %v" , err )
360+ }
361+ })
362+
363+ // Mixed-case names to verify OID-based lookups work (to_regclass lowercases unquoted identifiers).
364+ // rootTable is the unquoted form passed to PeerDB; rootTableDDL is the quoted form for SQL DDL.
365+ rootTable := schemaName + ".MultiLevel"
366+ rootTableDDL := schemaNameDDL + `."MultiLevel"`
367+ _ , err = conn .Exec (t .Context (), fmt .Sprintf (`
354368 CREATE TABLE %s (
355369 id SERIAL,
356370 region INT NOT NULL,
357371 category INT NOT NULL,
358372 value TEXT,
359373 PRIMARY KEY (region, category, id)
360374 ) PARTITION BY RANGE (region)
361- ` , rootTable ))
375+ ` , rootTableDDL ))
362376 require .NoError (t , err )
363377
364378 rowsPerPartition := 20
@@ -367,15 +381,15 @@ func TestCTIDPartitioningOnMultiLevelPartitionedTable(t *testing.T) {
367381
368382 // Two mid-level partitions, each sub-partitioned by category
369383 for r := range numMidLevelTables {
370- mid := fmt .Sprintf (" %s.region_ %d", schemaName , r )
384+ mid := fmt .Sprintf (` %s."Region_ %d"` , schemaNameDDL , r )
371385 _ , err = conn .Exec (t .Context (), fmt .Sprintf (
372386 `CREATE TABLE %s PARTITION OF %s FOR VALUES FROM (%d) TO (%d) PARTITION BY RANGE (category)` ,
373- mid , rootTable , r * 50 , (r + 1 )* 50 ))
387+ mid , rootTableDDL , r * 50 , (r + 1 )* 50 ))
374388 require .NoError (t , err )
375389
376390 // Three leaf partitions per mid-level
377391 for c := range numLeafChildTablesPerMidLevelTable {
378- leaf := fmt .Sprintf (" %s.region_%d_cat_ %d", schemaName , r , c )
392+ leaf := fmt .Sprintf (` %s."Region_%d_Cat_ %d"` , schemaNameDDL , r , c )
379393 _ , err = conn .Exec (t .Context (), fmt .Sprintf (
380394 `CREATE TABLE %s PARTITION OF %s FOR VALUES FROM (%d) TO (%d)` ,
381395 leaf , mid , c * 33 , (c + 1 )* 33 ))
@@ -384,14 +398,15 @@ func TestCTIDPartitioningOnMultiLevelPartitionedTable(t *testing.T) {
384398 }
385399
386400 // 6 leaf tables total, insert 20 rows into each
401+ // expectedLeaves uses unquoted names since that's what format('%s.%s', ...) in pg_class returns
387402 expectedLeaves := make ([]string , 0 , numLeafChildTablesPerMidLevelTable * numMidLevelTables )
388403 for r := range numMidLevelTables {
389404 for c := range numLeafChildTablesPerMidLevelTable {
390- leaf := fmt .Sprintf ("%s.region_%d_cat_ %d" , schemaName , r , c )
405+ leaf := fmt .Sprintf ("%s.Region_%d_Cat_ %d" , schemaName , r , c )
391406 expectedLeaves = append (expectedLeaves , leaf )
392407 for j := range rowsPerPartition {
393408 _ , err = conn .Exec (t .Context (), fmt .Sprintf (
394- `INSERT INTO %s (region, category, value) VALUES ($1, $2, $3)` , rootTable ),
409+ `INSERT INTO %s (region, category, value) VALUES ($1, $2, $3)` , rootTableDDL ),
395410 r * 50 , c * 33 + j % 33 , fmt .Sprintf ("v_%d_%d_%d" , r , c , j ))
396411 require .NoError (t , err )
397412 }
@@ -404,7 +419,7 @@ func TestCTIDPartitioningOnMultiLevelPartitionedTable(t *testing.T) {
404419 conn : conn ,
405420 logger : log .NewStructuredLogger (slog .With (slog .String (string (shared .FlowNameKey ), "testMultiLevel" ))),
406421 }
407- query := fmt .Sprintf (`SELECT * FROM %s WHERE ctid BETWEEN {{.start}} AND {{.end}}` , rootTable )
422+ query := fmt .Sprintf (`SELECT * FROM %s WHERE ctid BETWEEN {{.start}} AND {{.end}}` , rootTableDDL )
408423 partitions , err := c .GetQRepPartitions (t .Context (), & protos.QRepConfig {
409424 FlowJobName : "test_ctid_multi_level" ,
410425 NumRowsPerPartition : 10 ,
@@ -431,7 +446,7 @@ func TestCTIDPartitioningOnMultiLevelPartitionedTable(t *testing.T) {
431446 require .Positive (t , childTableCounts [leaf ])
432447 }
433448 for r := range numMidLevelTables {
434- mid := fmt .Sprintf ("%s.region_ %d" , schemaName , r )
449+ mid := fmt .Sprintf ("%s.Region_ %d" , schemaName , r )
435450 require .Zero (t , childTableCounts [mid ], mid )
436451 }
437452}
@@ -597,27 +612,42 @@ func TestCtidPartitionsForChildTablesOffsetNumberBounds(t *testing.T) {
597612
598613func TestCTIDPartitioningOnInheritedTable (t * testing.T ) {
599614 t .Parallel ()
600- schemaName , conn , connStr := setupTestSchema (t )
615+ _ , conn , connStr := setupTestSchema (t )
601616
602- parentTable := schemaName + ".parent_inh"
603- _ , err := conn .Exec (t .Context (), fmt .Sprintf (`CREATE TABLE %s (id SERIAL PRIMARY KEY, value TEXT)` , parentTable ))
617+ // Use a mixed-case schema name as well to verify OID-based lookups work
618+ // for both schema and table identifiers (to_regclass lowercases unquoted identifiers).
619+ schemaName := "Test_" + shared .RandomString (8 )
620+ schemaNameDDL := `"` + schemaName + `"`
621+ _ , err := conn .Exec (t .Context (), `CREATE SCHEMA ` + schemaNameDDL )
622+ require .NoError (t , err )
623+ t .Cleanup (func () {
624+ if _ , err := conn .Exec (t .Context (), `DROP SCHEMA ` + schemaNameDDL + ` CASCADE` ); err != nil {
625+ t .Logf ("Failed to drop schema: %v" , err )
626+ }
627+ })
628+
629+ // Mixed-case names to verify OID-based lookups work (to_regclass lowercases unquoted identifiers).
630+ // parentTable is the unquoted form passed to PeerDB; parentTableDDL is the quoted form for SQL DDL.
631+ parentTable := schemaName + ".ParentInh"
632+ parentTableDDL := schemaNameDDL + `."ParentInh"`
633+ _ , err = conn .Exec (t .Context (), fmt .Sprintf (`CREATE TABLE %s (id SERIAL PRIMARY KEY, value TEXT)` , parentTableDDL ))
604634 require .NoError (t , err )
605635
606636 numChildren := 3
607637 rowsPerTable := 20
608- childTables := make ([]string , numChildren )
638+ childTablesDDL := make ([]string , numChildren )
609639 for i := range numChildren {
610- childTables [i ] = fmt .Sprintf (" %s.child_inh_ %d", schemaName , i )
611- _ , err = conn .Exec (t .Context (), fmt .Sprintf (`CREATE TABLE %s () INHERITS (%s)` , childTables [i ], parentTable ))
640+ childTablesDDL [i ] = fmt .Sprintf (` %s."ChildInh_ %d"` , schemaNameDDL , i )
641+ _ , err = conn .Exec (t .Context (), fmt .Sprintf (`CREATE TABLE %s () INHERITS (%s)` , childTablesDDL [i ], parentTableDDL ))
612642 require .NoError (t , err )
613643 }
614644
615645 for j := range rowsPerTable {
616646 _ , err = conn .Exec (t .Context (), fmt .Sprintf (
617- `INSERT INTO %s (value) VALUES ($1)` , parentTable ), fmt .Sprintf ("parent_%d" , j ))
647+ `INSERT INTO %s (value) VALUES ($1)` , parentTableDDL ), fmt .Sprintf ("parent_%d" , j ))
618648 require .NoError (t , err )
619649 }
620- for i , child := range childTables {
650+ for i , child := range childTablesDDL {
621651 for j := range rowsPerTable {
622652 _ , err = conn .Exec (t .Context (), fmt .Sprintf (
623653 `INSERT INTO %s (value) VALUES ($1)` , child ), fmt .Sprintf ("child_%d_%d" , i , j ))
@@ -648,10 +678,11 @@ func TestCTIDPartitioningOnInheritedTable(t *testing.T) {
648678 childTablesCovered [ctr .Table ] = true
649679 }
650680 }
681+ // pg_class returns unquoted names from format('%s.%s', ...) so assertions use the unquoted form
651682 require .Len (t , childTablesCovered , 1 + numChildren )
652- require .True (t , childTablesCovered [parentTable ])
653- for _ , child := range childTables {
654- require .True (t , childTablesCovered [child ])
683+ require .True (t , childTablesCovered [schemaName + ".ParentInh" ])
684+ for i := range numChildren {
685+ require .True (t , childTablesCovered [fmt . Sprintf ( "%s.ChildInh_%d" , schemaName , i ) ])
655686 }
656687}
657688
0 commit comments