From: | Alexey Klyukin <alexk(at)commandprompt(dot)com> |
---|---|
To: | Noah Misch <noah(at)leadboat(dot)com> |
Cc: | Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Identifying no-op length coercions |
Date: | 2011-06-21 21:50:23 |
Message-ID: | 779549B8-475B-4F66-B55B-2A57552FF342@commandprompt.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Jun 21, 2011, at 9:58 PM, Noah Misch wrote:
>
> A pg_regress test needs stable output, so we would do it roughly like this:
>
> CREATE TEMP TABLE relstorage AS SELECT 0::regclass AS oldnode;
> ...
> UPDATE relstorage SET oldnode =
> (SELECT relfilenode FROM pg_class WHERE oid = 'test'::regclass);
> ALTER TABLE test ALTER name TYPE varchar(65535);
> SELECT oldnode <> relfilenode AS rewritten
> FROM pg_class, relstorage WHERE oid = 'test'::regclass;
>
> I originally rejected that as too ugly to read. Perhaps not.
Yes, your example is more appropriate. I think you can make it more
straightforward by getting rid of the temp table:
CREATE TABLE test(oldnode oid, name varchar(5));
INSERT INTO test(oldnode) SELECT relfilenode FROM pg_class WHERE
oid='test'::regclass;
ALTER TABLE test ALTER name TYPE varchar(10);
SELECT oldnode <> relfilenode AS rewritten FROM pg_class, test WHERE
oid='test'::regclass;
>
>> The only nitpick code-wise is these lines in varchar_transform:
>>
>> + int32 old_max = exprTypmod(source) - VARHDRSZ;
>> + int32 new_max = new_typmod - VARHDRSZ;
>>
>> I have a hard time understanding why VARHDRSZ is subtracted here, so I'd assume that's a bug.
>
> We track the varchar typmod internally as (max length) + VARHDRSZ.
Oh, right, haven't thought that this is a varchar specific thing.
Thank you,
Alexey.
--
Command Prompt, Inc. http://www.CommandPrompt.com
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2011-06-21 22:06:20 | Re: Fwd: Keywords in pg_hba.conf should be field-specific |
Previous Message | Pavel Stehule | 2011-06-21 21:47:12 | Re: patch for 9.2: enhanced errors |