11//! Foreign table schema query and data structures.
22
33use std:: collections:: { HashMap , HashSet } ;
4- use tracing:: debug;
4+ use tracing:: { debug, warn } ;
55
66use crate :: {
77 backend:: { schema:: postgres_fdw:: create_foreign_table, Server , ShardingSchema } ,
@@ -11,6 +11,7 @@ use crate::{
1111use super :: custom_types:: CustomTypes ;
1212use super :: extensions:: Extensions ;
1313use super :: quote_identifier;
14+ use super :: TypeMismatch ;
1415
1516/// Server definition for FDW setup.
1617#[ derive( Debug , Clone ) ]
@@ -134,18 +135,37 @@ impl ForeignTableSchema {
134135 self . custom_types . setup ( server) . await ?;
135136
136137 let mut tables = HashSet :: new ( ) ;
138+ let mut all_type_mismatches: Vec < TypeMismatch > = Vec :: new ( ) ;
139+
137140 for ( ( schema, table) , columns) in & self . tables {
141+ // Skip internal PgDog tables
142+ if Self :: is_internal_table ( schema, table) {
143+ continue ;
144+ }
145+
138146 let dedup = ( schema. clone ( ) , table. clone ( ) ) ;
139147 if !tables. contains ( & dedup) {
140- let statements = create_foreign_table ( columns, sharding_schema) ?;
141- for sql in statements {
148+ let result = create_foreign_table ( columns, sharding_schema) ?;
149+ for sql in & result . statements {
142150 debug ! ( "[fdw::setup] {} [{}]" , sql, server. addr( ) ) ;
143- server. execute ( & sql) . await ?;
151+ server. execute ( sql) . await ?;
144152 }
153+ all_type_mismatches. extend ( result. type_mismatches ) ;
145154 tables. insert ( dedup) ;
146155 }
147156 }
148157
158+ // Log summary of type mismatches if any were found
159+ if !all_type_mismatches. is_empty ( ) {
160+ warn ! (
161+ "[fdw] {} table(s) skipped due to sharding config type mismatches:" ,
162+ all_type_mismatches. len( )
163+ ) ;
164+ for mismatch in & all_type_mismatches {
165+ warn ! ( "[fdw] - {}" , mismatch) ;
166+ }
167+ }
168+
149169 server. execute ( "COMMIT" ) . await ?;
150170 Ok ( ( ) )
151171 }
@@ -182,6 +202,11 @@ impl ForeignTableSchema {
182202 & self . custom_types
183203 }
184204
205+ /// Check if a table is an internal PgDog table that shouldn't be exposed via FDW.
206+ fn is_internal_table ( schema : & str , table : & str ) -> bool {
207+ schema == "pgdog" && matches ! ( table, "validator_bigint" | "validator_uuid" | "config" )
208+ }
209+
185210 /// Collect unique schemas from tables and custom types.
186211 fn schemas ( & self ) -> HashSet < String > {
187212 self . tables
0 commit comments