pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedexplain plan difference
8+ messages / 3 participants
[nested] [flat]
* explain plan difference
@ 2019-11-04 03:14 Steve Baldwin <steve.baldwin@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Steve Baldwin @ 2019-11-04 03:14 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Can someone please help me understand this:
b2bc_dev=# *vacuum full analyze invoice;*
VACUUM
Time: 39.671 ms
b2bc_dev=# *create table invoice_copy as select * from invoice;*
SELECT 23
Time: 11.557 ms
b2bc_dev=# *alter table invoice_copy add primary key (id);*
ALTER TABLE
Time: 9.257 ms
b2bc_dev=# *vacuum full analyze invoice_copy;*
VACUUM
Time: 24.369 ms
b2bc_dev=# *explain analyze verbose select max(id::text) from invoice;*
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------
Aggregate (cost=4.40..4.41 rows=1 width=32) (actual time=0.852..0.878
rows=1 loops=1)
Output: max((id)::text)
-> Seq Scan on public.invoice (cost=0.00..4.23 rows=23 width=16)
(actual time=0.016..0.440 rows=23 loops=1)
Output: id
Planning time: 0.359 ms
Execution time: 1.063 ms
(6 rows)
Time: 4.266 ms
b2bc_dev=# *explain analyze verbose select max(id::text) from invoice_copy;*
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
Aggregate (cost=4.40..4.41 rows=1 width=32) (actual time=0.981..1.019
rows=1 loops=1)
Output: max((id)::text)
-> Seq Scan on public.invoice_copy (cost=0.00..4.23 rows=23 width=16)
(actual time=0.016..0.464 rows=23 loops=1)
Output: id, client_reference_id, buyer_id, seller_id,
invoice_date, invoice_due_date, invoice_total, po_number, details, status,
statement_id, invoice_reference_number, created, invoice_net,
ar_open_total, bill_date, return_total, api_client_id, client_id,
program_id, billing_payment_term_config_id, preauthorization_id,
tap_synced, updated, shipping_amount, tax_amount, foreign_exchange_fee,
foreign_exchange_fee_rate, return_foreign_exchange_fee,
original_shipping_amount, original_tax_amount, discount_amount,
original_discount_amount, shipping_tax_amount, shipping_discount_amount,
original_shipping_tax_amount, original_shipping_discount_amount,
captured_amount_seller, captured_amount_buyer, adjusted_amount, ar_closed_on
Planning time: 0.441 ms
Execution time: 1.254 ms
(6 rows)
b2bc_dev=# *select version();*
version
---------------------------------------------------------------------------------------
PostgreSQL 10.5 on x86_64-pc-linux-musl, compiled by gcc (Alpine 6.4.0)
6.4.0, 64-bit
(1 row)
Time: 4.916 ms
I guess the difference doesn't have a huge bearing (as far as I can tell)
on the result, but it just seems odd that the inner-most 'Output' step
outputs the entire row in the case of the copy and only the required field
in the case of the original table. What triggers that behaviour?
Thanks,
Steve
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: explain plan difference
@ 2019-11-04 04:01 Tom Lane <tgl@sss.pgh.pa.us>
parent: Steve Baldwin <steve.baldwin@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Tom Lane @ 2019-11-04 04:01 UTC (permalink / raw)
To: Steve Baldwin <steve.baldwin@gmail.com>; +Cc: pgsql-general@lists.postgresql.org
Steve Baldwin <steve.baldwin@gmail.com> writes:
> I guess the difference doesn't have a huge bearing (as far as I can tell)
> on the result, but it just seems odd that the inner-most 'Output' step
> outputs the entire row in the case of the copy and only the required field
> in the case of the original table. What triggers that behaviour?
The plan with the full output row is actually slightly cheaper, or at
least so the planner thinks, because it saves a projection step.
I imagine the reason you're not getting that with the original table
is that there are some dropped column(s) in the original table, forcing
the projection to be done to get rid of them.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: explain plan difference
@ 2019-11-04 04:03 Steve Baldwin <steve.baldwin@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: Steve Baldwin @ 2019-11-04 04:03 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general@lists.postgresql.org
Thanks very much for the explanation Tom !! You are correct - there are
dropped columns in the original.
Cheers,
Steve
On Mon, Nov 4, 2019 at 3:01 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Steve Baldwin <steve.baldwin@gmail.com> writes:
> > I guess the difference doesn't have a huge bearing (as far as I can tell)
> > on the result, but it just seems odd that the inner-most 'Output' step
> > outputs the entire row in the case of the copy and only the required
> field
> > in the case of the original table. What triggers that behaviour?
>
> The plan with the full output row is actually slightly cheaper, or at
> least so the planner thinks, because it saves a projection step.
> I imagine the reason you're not getting that with the original table
> is that there are some dropped column(s) in the original table, forcing
> the projection to be done to get rid of them.
>
> regards, tom lane
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: explain plan difference
@ 2019-11-04 12:04 Ravi Krishna <srkrishna@yahoo.com>
parent: Steve Baldwin <steve.baldwin@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Ravi Krishna @ 2019-11-04 12:04 UTC (permalink / raw)
To: Steve Baldwin <steve.baldwin@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-generallists.postgresql.org pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
> On Nov 3, 2019, at 11:03 PM, Steve Baldwin <steve.baldwin@gmail.com> wrote:
>
> Thanks very much for the explanation Tom !! You are correct - there are dropped columns in the original.
Just to confirm, we are talking about tables from where some cols were deleted in the past, but
VACUUM FULL not run on that table, right ?
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: explain plan difference
@ 2019-11-04 14:26 Tom Lane <tgl@sss.pgh.pa.us>
parent: Ravi Krishna <srkrishna@yahoo.com>
0 siblings, 1 reply; 8+ messages in thread
From: Tom Lane @ 2019-11-04 14:26 UTC (permalink / raw)
To: Ravi Krishna <srkrishna@yahoo.com>; +Cc: Steve Baldwin <steve.baldwin@gmail.com>; pgsql-general@lists.postgresql.org
Ravi Krishna <srkrishna@yahoo.com> writes:
>> On Nov 3, 2019, at 11:03 PM, Steve Baldwin <steve.baldwin@gmail.com> wrote:
>> Thanks very much for the explanation Tom !! You are correct - there are dropped columns in the original.
> Just to confirm, we are talking about tables from where some cols were deleted in the past, but
> VACUUM FULL not run on that table, right ?
VACUUM would not change the state of the dropped columns.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: explain plan difference
@ 2019-11-04 14:32 Ravi Krishna <srkrishna@yahoo.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: Ravi Krishna @ 2019-11-04 14:32 UTC (permalink / raw)
To: ; +Cc: pgsql-generallists.postgresql.org pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
>> Just to confirm, we are talking about tables from where some cols were deleted in the past, but
>> VACUUM FULL not run on that table, right ?
>
> VACUUM would not change the state of the dropped columns.
>
When does it change?
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: explain plan difference
@ 2019-11-04 14:45 Tom Lane <tgl@sss.pgh.pa.us>
parent: Ravi Krishna <srkrishna@yahoo.com>
0 siblings, 1 reply; 8+ messages in thread
From: Tom Lane @ 2019-11-04 14:45 UTC (permalink / raw)
To: Ravi Krishna <srkrishna@yahoo.com>; +Cc: pgsql-generallists.postgresql.org pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Ravi Krishna <srkrishna@yahoo.com> writes:
>> VACUUM would not change the state of the dropped columns.
> When does it change?
Never, unless you drop and recreate the table. Removing a dropped
column would change the attnums of following columns, which we
can't support because the tableoid+attnum is the only persistent
identifier of a column.
(From memory, operations like VACUUM FULL and CLUSTER will rewrite
dropped columns with NULLs to reduce their storage impact. But they
don't go away.)
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: explain plan difference
@ 2019-11-04 15:00 Ravi Krishna <srkrishna@yahoo.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Ravi Krishna @ 2019-11-04 15:00 UTC (permalink / raw)
To: ; +Cc: pgsql-generallists.postgresql.org pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
>
> Never, unless you drop and recreate the table. Removing a dropped
> column would change the attnums of following columns, which we
> can't support because the tableoid+attnum is the only persistent
> identifier of a column.
>
> (From memory, operations like VACUUM FULL and CLUSTER will rewrite
> dropped columns with NULLs to reduce their storage impact. But they
> don't go away.)
>
>
Thank you. I remember reading it here that VACUUM FULL does what you describe above.
So even TRUNCATE does not help here?
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2019-11-04 15:00 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-11-04 03:14 explain plan difference Steve Baldwin <steve.baldwin@gmail.com>
2019-11-04 04:01 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-11-04 04:03 ` Steve Baldwin <steve.baldwin@gmail.com>
2019-11-04 12:04 ` Ravi Krishna <srkrishna@yahoo.com>
2019-11-04 14:26 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-11-04 14:32 ` Ravi Krishna <srkrishna@yahoo.com>
2019-11-04 14:45 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-11-04 15:00 ` Ravi Krishna <srkrishna@yahoo.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox