EXPLAIN ANALYZE SELECT t_stamp FROM gw_stats.stats ORDER BY t_stamp DESC LIMIT 1; ---------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=169880.85..169880.85 rows=1 width=8) (actual time=53540.270..53540.276 rows=1 loops=1) -> Sort (cost=169880.85..173008.45 rows=1251039 width=8) (actual time=53540.257..53540.257 rows=1 loops=1) Sort Key: gw_stats.stats.t_stamp -> Result (cost=0.00..32110.39 rows=1251039 width=8) (actual time=0.071..39441.375 rows=1250266 loops=1) -> Append (cost=0.00..32110.39 rows=1251039 width=8) (actual time=0.059..24631.103 rows=1250266 loops=1) -> Seq Scan on stats (cost=0.00..13.20 rows=320 width=8) (actual time=0.006..0.006 rows=0 loops=1) -> Seq Scan on stats_200506 stats (cost=0.00..9541.20 rows=372020 width=8) (actual time=0.036..2530.075 rows=371769 loops=1) -> Seq Scan on stats_200507 stats (cost=0.00..9472.74 rows=369374 width=8) (actual time=0.035..3278.674 rows=369179 loops=1) -> Seq Scan on stats_200508 stats (cost=0.00..6023.53 rows=234753 width=8) (actual time=0.032..1661.003 rows=234808 loops=1) -> Seq Scan on stats_200509 stats (cost=0.00..365.77 rows=14177 width=8) (actual time=0.010..91.709 rows=14274 loops=1) -> Seq Scan on stats_200501 stats (cost=0.00..1.30 rows=30 width=8) (actual time=0.011..0.204 rows=30 loops=1) -> Seq Scan on stats_200502 stats (cost=0.00..117.81 rows=4581 width=8) (actual time=0.037..31.678 rows=4581 loops=1) -> Seq Scan on stats_200503 stats (cost=0.00..333.05 rows=12905 width=8) (actual time=0.035..84.913 rows=12905 loops=1) -> Seq Scan on stats_200504 stats (cost=0.00..805.40 rows=31140 width=8) (actual time=0.039..277.561 rows=31140 loops=1) -> Seq Scan on stats_200505 stats (cost=0.00..5436.39 rows=211739 width=8) (actual time=0.040..1549.011 rows=211580 loops=1) Total runtime: 53556.986 ms ---------------------------------------------------------------------------------------------------------------------------------------------------- Which is roughly equivalent to: EXPLAIN ANALYZE SELECT t_stamp FROM ONLY gw_stats.stats UNION ALL SELECT t_stamp FROM gw_stats.stats_200501 UNION ALL SELECT t_stamp FROM gw_stats.stats_200502 UNION ALL SELECT t_stamp FROM gw_stats.stats_200503 UNION ALL SELECT t_stamp FROM gw_stats.stats_200504 UNION ALL SELECT t_stamp FROM gw_stats.stats_200505 UNION ALL SELECT t_stamp FROM gw_stats.stats_200506 UNION ALL SELECT t_stamp FROM gw_stats.stats_200507 UNION ALL SELECT t_stamp FROM gw_stats.stats_200508 UNION ALL SELECT t_stamp FROM gw_stats.stats_200509 ORDER BY t_stamp DESC LIMIT 1; ---------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=182178.14..182178.14 rows=1 width=8) (actual time=58783.069..58783.075 rows=1 loops=1) -> Sort (cost=182178.14..185302.26 rows=1249647 width=8) (actual time=58783.051..58783.051 rows=1 loops=1) Sort Key: t_stamp -> Append (cost=0.00..44570.94 rows=1249647 width=8) (actual time=0.058..44601.547 rows=1248877 loops=1) -> Subquery Scan "*SELECT* 1" (cost=0.00..16.40 rows=320 width=8) (actual time=0.017..0.017 rows=0 loops=1) -> Seq Scan on stats (cost=0.00..13.20 rows=320 width=8) (actual time=0.006..0.006 rows=0 loops=1) -> Subquery Scan "*SELECT* 2" (cost=0.00..1.60 rows=30 width=8) (actual time=0.024..0.533 rows=30 loops=1) -> Seq Scan on stats_200501 (cost=0.00..1.30 rows=30 width=8) (actual time=0.013..0.204 rows=30 loops=1) -> Subquery Scan "*SELECT* 3" (cost=0.00..163.62 rows=4581 width=8) (actual time=0.068..81.795 rows=4581 loops=1) -> Seq Scan on stats_200502 (cost=0.00..117.81 rows=4581 width=8) (actual time=0.057..31.186 rows=4581 loops=1) -> Subquery Scan "*SELECT* 4" (cost=0.00..462.10 rows=12905 width=8) (actual time=0.046..230.967 rows=12905 loops=1) -> Seq Scan on stats_200503 (cost=0.00..333.05 rows=12905 width=8) (actual time=0.033..87.605 rows=12905 loops=1) -> Subquery Scan "*SELECT* 5" (cost=0.00..1116.80 rows=31140 width=8) (actual time=0.051..553.689 rows=31140 loops=1) -> Seq Scan on stats_200504 (cost=0.00..805.40 rows=31140 width=8) (actual time=0.037..197.642 rows=31140 loops=1) -> Subquery Scan "*SELECT* 6" (cost=0.00..7553.78 rows=211739 width=8) (actual time=0.063..4753.960 rows=211580 loops=1) -> Seq Scan on stats_200505 (cost=0.00..5436.39 rows=211739 width=8) (actual time=0.035..2133.092 rows=211580 loops=1) -> Subquery Scan "*SELECT* 7" (cost=0.00..13261.40 rows=372020 width=8) (actual time=0.043..7178.521 rows=371769 loops=1) -> Seq Scan on stats_200506 (cost=0.00..9541.20 rows=372020 width=8) (actual time=0.031..2632.163 rows=371769 loops=1) -> Subquery Scan "*SELECT* 8" (cost=0.00..13166.48 rows=369374 width=8) (actual time=0.049..8289.331 rows=369179 loops=1) -> Seq Scan on stats_200507 (cost=0.00..9472.74 rows=369374 width=8) (actual time=0.035..3171.864 rows=369179 loops=1) -> Subquery Scan "*SELECT* 9" (cost=0.00..8371.06 rows=234753 width=8) (actual time=0.049..7465.002 rows=234808 loops=1) -> Seq Scan on stats_200508 (cost=0.00..6023.53 rows=234753 width=8) (actual time=0.037..2555.151 rows=234808 loops=1) -> Subquery Scan "*SELECT* 10" (cost=0.00..457.70 rows=12785 width=8) (actual time=0.044..267.321 rows=12885 loops=1) -> Seq Scan on stats_200509 (cost=0.00..329.85 rows=12785 width=8) (actual time=0.032..118.810 rows=12885 loops=1) Total runtime: 58798.373 ms ---------------------------------------------------------------------------------------------------------------------------------------------- And would instead better perform if translated to: EXPLAIN ANALYZE (SELECT t_stamp FROM ONLY gw_stats.stats ORDER BY t_stamp DESC LIMIT 1) UNION ALL (SELECT t_stamp FROM gw_stats.stats_200501 ORDER BY t_stamp DESC LIMIT 1) UNION ALL (SELECT t_stamp FROM gw_stats.stats_200502 ORDER BY t_stamp DESC LIMIT 1) UNION ALL (SELECT t_stamp FROM gw_stats.stats_200503 ORDER BY t_stamp DESC LIMIT 1) UNION ALL (SELECT t_stamp FROM gw_stats.stats_200504 ORDER BY t_stamp DESC LIMIT 1) UNION ALL (SELECT t_stamp FROM gw_stats.stats_200505 ORDER BY t_stamp DESC LIMIT 1) UNION ALL (SELECT t_stamp FROM gw_stats.stats_200506 ORDER BY t_stamp DESC LIMIT 1) UNION ALL (SELECT t_stamp FROM gw_stats.stats_200507 ORDER BY t_stamp DESC LIMIT 1) UNION ALL (SELECT t_stamp FROM gw_stats.stats_200508 ORDER BY t_stamp DESC LIMIT 1) UNION ALL (SELECT t_stamp FROM gw_stats.stats_200509 ORDER BY t_stamp DESC LIMIT 1) ORDER BY t_stamp DESC LIMIT 1; --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=27.22..27.22 rows=1 width=8) (actual time=1.408..1.413 rows=1 loops=1) -> Sort (cost=27.22..27.24 rows=10 width=8) (actual time=1.395..1.395 rows=1 loops=1) Sort Key: t_stamp -> Append (cost=26.52..27.05 rows=10 width=8) (actual time=0.158..1.319 rows=9 loops=1) -> Subquery Scan "*SELECT* 1" (cost=26.52..26.53 rows=1 width=8) (actual time=0.041..0.041 rows=0 loops=1) -> Limit (cost=26.52..26.52 rows=1 width=8) (actual time=0.030..0.030 rows=0 loops=1) -> Sort (cost=26.52..27.32 rows=320 width=8) (actual time=0.020..0.020 rows=0 loops=1) Sort Key: t_stamp -> Seq Scan on stats (cost=0.00..13.20 rows=320 width=8) (actual time=0.007..0.007 rows=0 loops=1) -> Subquery Scan "*SELECT* 2" (cost=0.00..0.14 rows=1 width=8) (actual time=0.101..0.118 rows=1 loops=1) -> Limit (cost=0.00..0.13 rows=1 width=8) (actual time=0.090..0.095 rows=1 loops=1) -> Index Scan Backward using stats_200501_t_stamp_uc_id_key on stats_200501 (cost=0.00..3.77 rows=30 width=8) (actual time=0.078..0.078 rows=1 loops=1) -> Subquery Scan "*SELECT* 3" (cost=0.00..0.05 rows=1 width=8) (actual time=0.095..0.111 rows=1 loops=1) -> Limit (cost=0.00..0.04 rows=1 width=8) (actual time=0.084..0.090 rows=1 loops=1) -> Index Scan Backward using stats_200502_t_stamp_uc_id_key on stats_200502 (cost=0.00..173.89 rows=4581 width=8) (actual time=0.073..0.073 rows=1 loops=1) -> Subquery Scan "*SELECT* 4" (cost=0.00..0.05 rows=1 width=8) (actual time=0.093..0.110 rows=1 loops=1) -> Limit (cost=0.00..0.04 rows=1 width=8) (actual time=0.082..0.088 rows=1 loops=1) -> Index Scan Backward using stats_200503_t_stamp_uc_id_key on stats_200503 (cost=0.00..487.20 rows=12905 width=8) (actual time=0.070..0.070 rows=1 loops=1) -> Subquery Scan "*SELECT* 5" (cost=0.00..0.05 rows=1 width=8) (actual time=0.096..0.111 rows=1 loops=1) -> Limit (cost=0.00..0.04 rows=1 width=8) (actual time=0.084..0.089 rows=1 loops=1) -> Index Scan Backward using stats_200504_t_stamp_uc_id_key on stats_200504 (cost=0.00..1174.66 rows=31140 width=8) (actual time=0.072..0.072 rows=1 loops=1) -> Subquery Scan "*SELECT* 6" (cost=0.00..0.05 rows=1 width=8) (actual time=0.110..0.127 rows=1 loops=1) -> Limit (cost=0.00..0.04 rows=1 width=8) (actual time=0.098..0.103 rows=1 loops=1) -> Index Scan Backward using stats_200505_t_stamp_uc_id_key on stats_200505 (cost=0.00..8081.03 rows=211739 width=8) (actual time=0.087..0.087 rows=1 loops=1) -> Subquery Scan "*SELECT* 7" (cost=0.00..0.05 rows=1 width=8) (actual time=0.135..0.150 rows=1 loops=1) -> Limit (cost=0.00..0.04 rows=1 width=8) (actual time=0.123..0.128 rows=1 loops=1) -> Index Scan Backward using stats_200506_t_stamp_uc_id_key on stats_200506 (cost=0.00..14449.91 rows=372020 width=8) (actual time=0.112..0.112 rows=1 loops=1) -> Subquery Scan "*SELECT* 8" (cost=0.00..0.05 rows=1 width=8) (actual time=0.115..0.131 rows=1 loops=1) -> Limit (cost=0.00..0.04 rows=1 width=8) (actual time=0.104..0.109 rows=1 loops=1) -> Index Scan Backward using stats_200507_t_stamp_uc_id_key on stats_200507 (cost=0.00..14346.43 rows=369374 width=8) (actual time=0.092..0.092 rows=1 loops=1) -> Subquery Scan "*SELECT* 9" (cost=0.00..0.05 rows=1 width=8) (actual time=0.116..0.132 rows=1 loops=1) -> Limit (cost=0.00..0.04 rows=1 width=8) (actual time=0.104..0.110 rows=1 loops=1) -> Index Scan Backward using stats_200508_t_stamp_uc_id_key on stats_200508 (cost=0.00..9124.53 rows=234753 width=8) (actual time=0.093..0.093 rows=1 loops=1) -> Subquery Scan "*SELECT* 10" (cost=0.00..0.05 rows=1 width=8) (actual time=0.111..0.128 rows=1 loops=1) -> Limit (cost=0.00..0.04 rows=1 width=8) (actual time=0.100..0.105 rows=1 loops=1) -> Index Scan Backward using stats_200509_t_stamp_uc_id_key on stats_200509 (cost=0.00..555.95 rows=14177 width=8) (actual time=0.088..0.088 rows=1 loops=1) Total runtime: 1.663 ms ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------