Re: Typmod associated with multi-row VALUES constructs
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>
Cc: david.g.johnston@gmail.com, pgsql-hackers@postgresql.org
Date: 2016-12-08T20:58:10Z
Lists: pgsql-hackers
Attachments
- fix-VALUES-RTE-typmods-9.6.patch (text/x-diff) patch
I've pushed the previous patch to HEAD. Attached is a proposed patch
(against 9.6) that we could use for the back branches; it takes the
brute force approach of just computing the correct value on-demand
in the two functions at issue. The key question of course is whether
this is acceptable from a performance standpoint. I did a simple test
using a 1000-entry VALUES list:
select count(a) from (
values
('0'::varchar(3), '0'::varchar(4)),
('1'::varchar(3), '1'::varchar(4)),
('2'::varchar(3), '2'::varchar(4)),
('3'::varchar(3), '3'::varchar(4)),
('4'::varchar(3), '4'::varchar(4)),
...
('996'::varchar(3), '996'::varchar(4)),
('997'::varchar(3), '997'::varchar(4)),
('998'::varchar(3), '998'::varchar(4)),
('999'::varchar(3), '999'::varchar(4))
) v(a,b);
Since all the rows do have the same typmod, this represents the worst
case where we have to scan all the way to the end to confirm the typmod,
and it has about as little overhead otherwise as I could think of doing.
I ran it like this:
pgbench -U postgres -n -c 1 -T 1000 -f bigvalues.sql regression
and could not see any above-the-noise-level difference --- in fact,
it seemed like it was faster *with* the patch, which is obviously
impossible; I blame that on chance realignments of loops vs. cache
line boundaries.
So I think this is an okay candidate for back-patching. If anyone
wants to do their own performance tests, please do.
regards, tom lane
Commits
-
Fix reporting of column typmods for multi-row VALUES constructs.
- cf22c8cb8900 9.6.2 landed
- c7a62135acfb 9.4.11 landed
- 6a493adda745 9.5.6 landed
- 2afe282a3732 9.3.16 landed
- 082d1fb9e4ec 9.2.20 landed
- 0b78106cd465 10.0 landed