File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ def count_estimate(query)
4242 private
4343
4444 def get_table_estimate ( table_name )
45+ quoted_table = quote_value ( table_name . to_s )
46+
4547 # Enhanced estimation using both reltuples and live stats
4648 result = execute_sql ( <<~SQL )
4749 SELECT COALESCE(
@@ -57,7 +59,7 @@ def get_table_estimate(table_name)
5759 )::bigint AS estimated_count
5860 FROM pg_class
5961 LEFT JOIN pg_stat_user_tables pg_stat ON pg_stat.relid = pg_class.oid
60- WHERE pg_class.oid = ' #{ table_name } ' ::regclass
62+ WHERE pg_class.oid = #{ quoted_table } ::regclass
6163
6264 -- Handle partitioned tables
6365 UNION ALL
@@ -71,7 +73,7 @@ def get_table_estimate(table_name)
7173 FROM pg_inherits
7274 JOIN pg_class ON pg_inherits.inhrelid = pg_class.oid
7375 LEFT JOIN pg_stat_user_tables pg_stat ON pg_stat.relid = pg_class.oid
74- WHERE pg_inherits.inhparent = ' #{ table_name } ' ::regclass
76+ WHERE pg_inherits.inhparent = #{ quoted_table } ::regclass
7577 SQL
7678
7779 # Get the maximum estimate (handles both regular and partitioned tables)
You can’t perform that action at this time.
0 commit comments