@@ -1012,9 +1012,17 @@ async fn query_keyspaces(
10121012
10131013 let ( mut all_tables, mut all_views, mut all_user_defined_types) = if fetch_schema {
10141014 let udts = query_user_defined_types ( conn, keyspaces_to_fetch) . await ?;
1015+ let mut tables_schema = query_tables_schema ( conn, keyspaces_to_fetch, & udts) . await ?;
10151016 (
1016- query_tables ( conn, keyspaces_to_fetch, & udts) . await ?,
1017- query_views ( conn, keyspaces_to_fetch, & udts) . await ?,
1017+ // We pass the mutable reference to the same map to the both functions.
1018+ // First function fetches `system_schema.tables`, and removes found
1019+ // table from `tables_schema`.
1020+ // Second does the same for `system_schema.views`.
1021+ // The assumption here is that no keys (table names) can appear in both
1022+ // of those schema table.
1023+ // As far as we know this assumption is true for Scylla and Cassandra.
1024+ query_tables ( conn, keyspaces_to_fetch, & mut tables_schema) . await ?,
1025+ query_views ( conn, keyspaces_to_fetch, & mut tables_schema) . await ?,
10181026 udts,
10191027 )
10201028 } else {
@@ -1411,7 +1419,7 @@ mod toposort_tests {
14111419async fn query_tables (
14121420 conn : & Arc < Connection > ,
14131421 keyspaces_to_fetch : & [ String ] ,
1414- udts : & HashMap < String , HashMap < String , Arc < UserDefinedType > > > ,
1422+ tables : & mut HashMap < ( String , String ) , Table > ,
14151423) -> Result < HashMap < String , HashMap < String , Table > > , QueryError > {
14161424 let rows = query_filter_keyspace_name :: < ( String , String ) > (
14171425 conn,
@@ -1420,7 +1428,6 @@ async fn query_tables(
14201428 |err| MetadataError :: Tables ( TablesMetadataError :: SchemaTablesInvalidColumnType ( err) ) ,
14211429 ) ;
14221430 let mut result = HashMap :: new ( ) ;
1423- let mut tables = query_tables_schema ( conn, keyspaces_to_fetch, udts) . await ?;
14241431
14251432 rows. map ( |row_result| {
14261433 let keyspace_and_table_name = row_result?;
@@ -1448,7 +1455,7 @@ async fn query_tables(
14481455async fn query_views (
14491456 conn : & Arc < Connection > ,
14501457 keyspaces_to_fetch : & [ String ] ,
1451- udts : & HashMap < String , HashMap < String , Arc < UserDefinedType > > > ,
1458+ tables : & mut HashMap < ( String , String ) , Table > ,
14521459) -> Result < HashMap < String , HashMap < String , MaterializedView > > , QueryError > {
14531460 let rows = query_filter_keyspace_name :: < ( String , String , String ) > (
14541461 conn,
@@ -1458,7 +1465,6 @@ async fn query_views(
14581465 ) ;
14591466
14601467 let mut result = HashMap :: new ( ) ;
1461- let mut tables = query_tables_schema ( conn, keyspaces_to_fetch, udts) . await ?;
14621468
14631469 rows. map ( |row_result| {
14641470 let ( keyspace_name, view_name, base_table_name) = row_result?;
0 commit comments