Skip to content

Instantly share code, notes, and snippets.

@ailabs-software
Created September 15, 2019 02:32
Show Gist options
  • Save ailabs-software/04288075c8c1212c79d45d74e850f019 to your computer and use it in GitHub Desktop.
Save ailabs-software/04288075c8c1212c79d45d74e850f019 to your computer and use it in GitHub Desktop.
If there are 95040 rows matching status_executed=0, why isn't the number of publish_queue rows being joined on, not 562209?
# SELECT COUNT(*) FROM publish_queue WHERE status_executed=0;
count
-------
95040
(1 row)
madonna=# EXPLAIN ANALYZE
madonna-# SELECT maturation_timestamp FROM publish_queue LEFT OUTER JOIN publish ON(publish.id=publish_queue.publish_id) WHERE status_executed=0 AND funded AND syndicated=false ORDER BY NOT maturation_timestamp IS NULL, maturation_timestamp ASC LIMIT 1;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=193399.06..193399.06 rows=1 width=8) (actual time=1018.427..1018.427 rows=0 loops=1)
-> Sort (cost=193399.06..194706.22 rows=522866 width=8) (actual time=1018.427..1018.427 rows=0 loops=1)
Sort Key: ((publish_queue.maturation_timestamp IS NOT NULL)), publish_queue.maturation_timestamp
Sort Method: quicksort Memory: 25kB
-> Hash Join (cost=90812.53..190784.73 rows=522866 width=8) (actual time=1018.401..1018.401 rows=0 loops=1)
Hash Cond: (publish_queue.publish_id = publish.id)
-> Index Scan using publish_queue_status_executed_idx on publish_queue (cost=0.43..77041.65 rows=562209 width=24) (actual time=0.008..28.476 rows=95040 loops=1)
Index Cond: (status_executed = 0)
-> Hash (cost=68765.87..68765.87 rows=1268258 width=16) (actual time=751.910..751.910 rows=1219575 loops=1)
Buckets: 65536 Batches: 4 Memory Usage: 14321kB
-> Seq Scan on publish (cost=0.00..68765.87 rows=1268258 width=16) (actual time=0.015..472.213 rows=1219575 loops=1)
Filter: (funded AND (NOT syndicated))
Rows Removed by Filter: 89225
Total runtime: 1019.079 ms
(14 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment