@@ -28,7 +28,7 @@ mod ddl;
2828mod delete;
2929mod explain;
3030mod plugins;
31- pub mod schema_sharding;
31+ mod schema_sharding;
3232mod select;
3333mod set;
3434mod shared;
@@ -382,6 +382,46 @@ impl QueryParser {
382382 // with the fingerprint.
383383 //
384384 if route. shard ( ) . all ( ) {
385+ // Check search_path for schema.
386+ let search_path = context. router_context . params . get ( "search_path" ) ;
387+
388+ // Quick inline function to shard query
389+ // based on schema in search_path.
390+ fn shard_from_search_path (
391+ search_path : & str ,
392+ context : & QueryParserContext < ' _ > ,
393+ query_parser : & mut QueryParser ,
394+ route : & mut Route ,
395+ ) {
396+ let schema = Schema :: from ( search_path) ;
397+
398+ if let Some ( schema) = context. sharding_schema . schemas . get ( Some ( schema) ) {
399+ let shard: Shard = schema. shard ( ) . into ( ) ;
400+
401+ if let Some ( recorder) = query_parser. recorder_mut ( ) {
402+ recorder. record_entry (
403+ Some ( shard. clone ( ) ) ,
404+ format ! ( "matched schema {} in search_path" , schema. name( ) ) ,
405+ ) ;
406+ }
407+ route. set_shard_mut ( shard) ;
408+ }
409+ }
410+
411+ match search_path {
412+ Some ( ParameterValue :: String ( search_path) ) => {
413+ shard_from_search_path ( search_path, context, self , route) ;
414+ }
415+
416+ Some ( ParameterValue :: Tuple ( search_paths) ) => {
417+ for schema in search_paths {
418+ shard_from_search_path ( schema, context, self , route) ;
419+ }
420+ }
421+
422+ None => ( ) ,
423+ }
424+
385425 let databases = databases ( ) ;
386426 // Only fingerprint the query if some manual queries are configured.
387427 // Otherwise, we're wasting time parsing SQL.
@@ -469,6 +509,10 @@ impl QueryParser {
469509 context. split_insert_mode ( ) ,
470510 ) ?;
471511
512+ if let Some ( shard) = self . check_search_path_for_shard ( context) ? {
513+ return Ok ( Command :: Query ( Route :: write ( shard) ) ) ;
514+ }
515+
472516 match routing {
473517 InsertRouting :: Routed ( shard) => {
474518 if let Some ( recorder) = self . recorder_mut ( ) {
0 commit comments