Created
May 21, 2016 03:30
-
-
Save risent/f64d03fc4de7a88715921be79613ecbf to your computer and use it in GitHub Desktop.
limit parameter effect PostgreSQL query plan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bazaar4_13=# explain SELECT "store_snpool"."id", "store_snpool"."event_id", "store_snpool"."code" FROM "store_snpool" WHERE "store_snpool"."event_id" = 9967 ORDER | |
BY "store_snpool"."id" ASC LIMIT 1; | |
QUERY PLAN | |
----------------------------------------------------------------------------------------------------- | |
Limit (cost=0.43..61.15 rows=1 width=12) | |
-> Index Scan using store_snpool_pkey on store_snpool (cost=0.43..118529.70 rows=1952 width=12) | |
Filter: (event_id = 9967) | |
(3 rows) | |
bazaar4_13=# explain SELECT "store_snpool"."id", "store_snpool"."event_id", "store_snpool"."code" FROM "store_snpool" WHERE "store_snpool"."event_id" = 9967 ORDER | |
BY "store_snpool"."id" ASC LIMIT 2; | |
QUERY PLAN | |
----------------------------------------------------------------------------------------------------- | |
Limit (cost=0.43..121.87 rows=2 width=12) | |
-> Index Scan using store_snpool_pkey on store_snpool (cost=0.43..118529.70 rows=1952 width=12) | |
Filter: (event_id = 9967) | |
(3 rows) | |
bazaar4_13=# explain SELECT "store_snpool"."id", "store_snpool"."event_id", "store_snpool"."code" FROM "store_snpool" WHERE "store_snpool"."event_id" = 9967 ORDER | |
BY "store_snpool"."id" ASC LIMIT 3; | |
QUERY PLAN | |
------------------------------------------------------------------------------------------------------------ | |
Limit (cost=158.99..159.00 rows=3 width=12) | |
-> Sort (cost=158.99..163.87 rows=1952 width=12) | |
Sort Key: id | |
-> Index Scan using store_snpool_event_id on store_snpool (cost=0.43..133.76 rows=1952 width=12) | |
Index Cond: (event_id = 9967) | |
(5 rows) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bazaar4_13=# \d store_snpool | |
Table "public.store_snpool" | |
Column | Type | Modifiers | |
----------+---------+----------------------------------------------------------- | |
id | integer | not null default nextval('store_snpool_id_seq'::regclass) | |
event_id | integer | not null | |
code | integer | not null default 0 | |
Indexes: | |
"store_snpool_pkey" PRIMARY KEY, btree (id) | |
"store_snpool_event_id" btree (event_id) | |
Check constraints: | |
"store_snpool_code_check" CHECK (code >= 0) | |
Foreign-key constraints: | |
"event_id_refs_id_455fd5f3243b48eb" FOREIGN KEY (event_id) REFERENCES store_event(id) DEFERRABLE INITIALLY DEFERRED |
Author
risent
commented
Aug 30, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment