Skip to content

Omnisharded tables routing fix#618

Merged
levkk merged 3 commits intomainfrom
levkk-omni-fixes
Nov 21, 2025
Merged

Omnisharded tables routing fix#618
levkk merged 3 commits intomainfrom
levkk-omni-fixes

Conversation

@levkk
Copy link
Copy Markdown
Collaborator

@levkk levkk commented Nov 21, 2025

Description

  • Omnisharded tables detection in SELECT handler wasn't parsing table names correctly from the FROM clause, i.e. didn't support joins.
  • Fix expanded explain with omni tables.
pgdog=# explain SELECT n.nspname as "Schema",
pgdog-#   c.relname as "Name",
pgdog-#   CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 't' THEN 'TOAST table' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' WHEN 'I' THEN 'partitioned index' END as "Type",
pgdog-#   pg_catalog.pg_get_userbyid(c.relowner) as "Owner",
pgdog-#   CASE c.relpersistence WHEN 'p' THEN 'permanent' WHEN 't' THEN 'temporary' WHEN 'u' THEN 'unlogged' END as "Persistence",
pgdog-#   am.amname as "Access method",
pgdog-#   pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as "Size",
pgdog-#   pg_catalog.obj_description(c.oid, 'pg_class') as "Description"
pgdog-# FROM pg_catalog.pg_class c
pgdog-#      LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
pgdog-#      LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam
pgdog-# WHERE c.relkind IN ('r','p','v','m','S','f','')
pgdog-#       AND n.nspname <> 'pg_catalog'
pgdog-#       AND n.nspname !~ '^pg_toast'
pgdog-#       AND n.nspname <> 'information_schema'
pgdog-#   AND pg_catalog.pg_table_is_visible(c.oid)
pgdog-# ORDER BY 1,2;
                                                                        QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------
 Result  (cost=36.89..47.39 rows=35 width=384)
   ->  Sort  (cost=36.89..36.98 rows=35 width=324)
         Sort Key: n.nspname, c.relname
         ->  Hash Left Join  (cost=2.25..35.99 rows=35 width=324)
               Hash Cond: (c.relam = am.oid)
               ->  Hash Join  (cost=1.09..33.55 rows=35 width=142)
                     Hash Cond: (c.relnamespace = n.oid)
                     ->  Seq Scan on pg_class c  (cost=0.00..32.07 rows=70 width=82)
                           Filter: ((relkind = ANY ('{r,p,v,m,S,f,""}'::"char"[])) AND pg_table_is_visible(oid))
                     ->  Hash  (cost=1.07..1.07 rows=2 width=68)
                           ->  Seq Scan on pg_namespace n  (cost=0.00..1.07 rows=2 width=68)
                                 Filter: ((nspname <> 'pg_catalog'::name) AND (nspname !~ '^pg_toast'::text) AND (nspname <> 'information_schema'::name))
               ->  Hash  (cost=1.07..1.07 rows=7 width=68)
                     ->  Seq Scan on pg_am am  (cost=0.00..1.07 rows=7 width=68)

 PgDog Routing:
   Summary: shard=1 role=replica
   Shard 1: SELECT matched omnisharded tables: pg_class, pg_namespace, pg_am
(18 rows)

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 21, 2025

Codecov Report

❌ Patch coverage is 84.28571% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pgdog/src/frontend/router/parser/query/select.rs 60.86% 9 Missing ⚠️
pgdog/src/frontend/router/parser/from_clause.rs 95.65% 1 Missing ⚠️
pgdog/src/frontend/router/parser/where_clause.rs 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@levkk levkk merged commit bd7f3e2 into main Nov 21, 2025
8 checks passed
@levkk levkk deleted the levkk-omni-fixes branch November 21, 2025 18:07
dev-lew pushed a commit to dev-lew/pgdog that referenced this pull request Feb 18, 2026
* Fix omnishard tables detection

* Tests

* make explain work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant