pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Partial indexes on VARCHAR get double converted from text
3+ messages / 2 participants
[nested] [flat]

* Partial indexes on VARCHAR get double converted from text
@ 2015-01-15 22:43  Josh Berkus <josh@agliodbs.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Josh Berkus @ 2015-01-15 22:43 UTC (permalink / raw)
  To: pgsql-bugs

create table stately ( id int, filename varchar(255), state varchar(255) );

create index on stately(state) where state in ( 'pending', 'waiting',
'done' );

\d stately
            Table "public.stately"
  Column  |          Type          | Modifiers
----------+------------------------+-----------
 id       | integer                |
 filename | character varying(255) |
 state    | character varying(255) |
Indexes:
    "stately_state_idx" btree (state) WHERE state::text = ANY
(ARRAY['pending'::character varying, 'waiting'::character varying,
'done'::character varying]::text[])

There is no combination of typecasting which will prevent this outcome.
 I've tried.

Further, it seems to me from testing that this double type conversion
affects the planner's costing of the index, causing it to not want to
use the index.

-- 
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Partial indexes on VARCHAR get double converted from text
@ 2015-01-16 01:52  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Josh Berkus <josh@agliodbs.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2015-01-16 01:52 UTC (permalink / raw)
  To: Josh Berkus <josh@agliodbs.com>; +Cc: pgsql-bugs

Josh Berkus <josh@agliodbs.com> writes:
> create table stately ( id int, filename varchar(255), state varchar(255) );
> create index on stately(state) where state in ( 'pending', 'waiting',
> 'done' );

> \d stately
>             Table "public.stately"
>   Column  |          Type          | Modifiers
> ----------+------------------------+-----------
>  id       | integer                |
>  filename | character varying(255) |
>  state    | character varying(255) |
> Indexes:
>     "stately_state_idx" btree (state) WHERE state::text = ANY
> (ARRAY['pending'::character varying, 'waiting'::character varying,
> 'done'::character varying]::text[])

I see no bug here.  It's doing what's expected.

> Further, it seems to me from testing that this double type conversion
> affects the planner's costing of the index, causing it to not want to
> use the index.

That's not a bug report, that's just unsupported speculation.  Moreover,
if there were any such effect, it would cause the planner to reject the
index entirely, not just penalize it cost-wise.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Partial indexes on VARCHAR get double converted from text
@ 2015-01-16 03:24  Josh Berkus <josh@agliodbs.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Josh Berkus @ 2015-01-16 03:24 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

On 01/16/2015 02:52 PM, Tom Lane wrote:
> Josh Berkus <josh@agliodbs.com> writes:
>> create table stately ( id int, filename varchar(255), state varchar(255) );
>> create index on stately(state) where state in ( 'pending', 'waiting',
>> 'done' );
> 
>> \d stately
>>             Table "public.stately"
>>   Column  |          Type          | Modifiers
>> ----------+------------------------+-----------
>>  id       | integer                |
>>  filename | character varying(255) |
>>  state    | character varying(255) |
>> Indexes:
>>     "stately_state_idx" btree (state) WHERE state::text = ANY
>> (ARRAY['pending'::character varying, 'waiting'::character varying,
>> 'done'::character varying]::text[])
> 
> I see no bug here.  It's doing what's expected.

Why have the multiple conversions to and from TEXT?  It's certainly
visually confusing to users.

> 
>> Further, it seems to me from testing that this double type conversion
>> affects the planner's costing of the index, causing it to not want to
>> use the index.
> 
> That's not a bug report, that's just unsupported speculation.  Moreover,
> if there were any such effect, it would cause the planner to reject the
> index entirely, not just penalize it cost-wise.

I thought I had a test case which showed different costing for varchar
vs. text, but the results are more confusing than that.  Will delve further.

-- 
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2015-01-16 03:24 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-01-15 22:43 Partial indexes on VARCHAR get double converted from text Josh Berkus <josh@agliodbs.com>
2015-01-16 01:52 ` Tom Lane <tgl@sss.pgh.pa.us>
2015-01-16 03:24   ` Josh Berkus <josh@agliodbs.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