@@ -64,6 +64,17 @@ def table_stats_query(connection)
6464 end
6565
6666 def build_table_stats_query ( connection )
67+ case connection . adapter_name
68+ when "Mysql2" , "Trilogy"
69+ build_mysql_table_stats_query ( connection )
70+ when "PostgreSQL"
71+ build_postgresql_table_stats_query ( connection )
72+ else
73+ ''
74+ end
75+ end
76+
77+ def build_mysql_table_stats_query ( connection )
6778 tables = connection . select_values ( <<-SQL )
6879 SELECT table_name
6980 FROM information_schema.tables
@@ -76,8 +87,22 @@ def build_table_stats_query(connection)
7687 queries . join ( ' UNION ALL ' )
7788 end
7889
90+ def build_postgresql_table_stats_query ( connection )
91+ tables = connection . select_values ( <<-SQL )
92+ SELECT table_name
93+ FROM information_schema.tables
94+ WHERE table_schema = current_schema()
95+ AND table_type = 'BASE TABLE'
96+ AND #{ self . class . exclusion_condition ( 'table_name' ) } ;
97+ SQL
98+ queries = tables . map do |table |
99+ "(SELECT #{ connection . quote ( table ) } FROM #{ connection . quote_table_name ( table ) } LIMIT 1)"
100+ end
101+ queries . join ( ' UNION ALL ' )
102+ end
103+
79104 def information_schema_exists? connection
80- [ "Mysql2" , "Trilogy" ] . include? ( connection . adapter_name )
105+ [ "Mysql2" , "Trilogy" , "PostgreSQL" ] . include? ( connection . adapter_name )
81106 end
82107 end
83108 end
0 commit comments