Query plan when using currval
От | Steve Baldwin |
---|---|
Тема | Query plan when using currval |
Дата | |
Msg-id | CAKE1Aib_H1Si0wNv+27-RKNGoKv+afmciZhxPaKsoYrMfSAJfw@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Query plan when using currval
Re: Query plan when using currval |
Список | pgsql-novice |
Hi,
Steve
Can someone please help me understand why the first query doesn't use the primary key index whereas the second query does use it:
bcaas=> explain analyze select id from log_statement where id = currval('log_statement_id_seq');
QUERY PLAN
--------------------------------------------------------------------------------------------------------
Seq Scan on log_statement (cost=0.00..14.05 rows=1 width=8) (actual time=0.027..0.027 rows=0 loops=1)
Filter: (id = currval('log_statement_id_seq'::regclass))
Rows Removed by Filter: 9
Planning time: 0.081 ms
Execution time: 0.048 ms
(5 rows)
bcaas=> explain analyze select id from log_statement where id = (select currval('log_statement_id_seq'));
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------
Index Only Scan using log_statement_pkey on log_statement (cost=0.16..8.18 rows=1 width=8) (actual time=0.017..0.017 rows=0 loops=1)
Index Cond: (id = $0)
Heap Fetches: 0
InitPlan 1 (returns $0)
-> Result (cost=0.00..0.01 rows=1 width=8) (actual time=0.003..0.004 rows=1 loops=1)
Planning time: 0.105 ms
Execution time: 0.045 ms
(7 rows)
(This is with pg 10.3)
Thanks,
Steve
В списке pgsql-novice по дате отправления: