Em 23/09/2019 16:03, Luís Roberto Weck escreveu:Em 23/09/2019 15:43, nikhil raj escreveu: This is the query that is actually slow: -- EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS) SELECT table_schema, table_name, n_live_tup::numeric as est_rows, pg_table_size(relid)::numeric as table_size FROM information_schema.columns JOIN pg_stat_user_tables as psut ON table_schema = psut.schemaname AND table_name = psut.relname LEFT JOIN pg_stats ON table_schema = pg_stats.schemaname AND table_name = pg_stats.tablename AND column_name = attname WHERE attname IS NULL AND table_schema NOT IN ('pg_catalog', 'information_schema') GROUP BY table_schema, table_name, relid, n_live_tup If I turn the left join to a inner join, the query runs very fast. Plans: LEFT JOIN: https://explain.depesz.com/s/i88x INNER JOIN: https://explain.depesz.com/s/ciSu Ofcourse, that's not what the full query needs |