Re: Query plan when using currval
От | Steve Baldwin |
---|---|
Тема | Re: Query plan when using currval |
Дата | |
Msg-id | CAKE1Aia6vBGWdkFngyoWu3xH-mZPU4AmP5W5mG0Ws_pV7n_QFQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Query plan when using currval (David Rowley <david.rowley@2ndquadrant.com>) |
Список | pgsql-novice |
Thanks Tom and David. My current logic flow was to do an insert and then a bit later, and update the same row. The update was using 'where id = currval(...)' and was getting slower and slower as the table grew (surprise surprise). I realise I can solve my performance issue in a couple of ways, but I think I'm going to refactor it and try to avoid the update.
I really appreciate the insight.
Steve
On Thu, May 10, 2018 at 8:22 AM, David Rowley <david.rowley@2ndquadrant.com> wrote:
On 9 May 2018 at 18:24, Steve Baldwin <steve.baldwin@gmail.com> wrote:
> bcaas=> explain analyze select id from log_statement where id = (select currval('log_statement_id_seq'));
I know Tom has answered your question, but you may be interested in
INSERT RETURNING as this will save you from having to do this to
lookup the ID of the last inserted sequence value.
https://www.postgresql.org/docs/10/static/sql-insert.html
--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
В списке pgsql-novice по дате отправления: