pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedindex not used in ( varchar = text )
6+ messages / 3 participants
[nested] [flat]
* index not used in ( varchar = text )
@ 2003-02-22 17:55 Gaetano Mendola <mendola@bigfoot.com>
0 siblings, 1 reply; 6+ messages in thread
From: Gaetano Mendola @ 2003-02-22 17:55 UTC (permalink / raw)
To: pgsql-admin
Hi all,
why in Postgresql 7.3.2 in a select like:
SELECT *
FROM user_login
WHERE login = 'FOO'::text;
and login is a VARCHAR the index on login
is not used anymore ?
Ciao
Gaetano
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: index not used in ( varchar = text )
@ 2003-02-23 18:07 Will LaShell <will@lashell.net>
parent: Gaetano Mendola <mendola@bigfoot.com>
0 siblings, 1 reply; 6+ messages in thread
From: Will LaShell @ 2003-02-23 18:07 UTC (permalink / raw)
To: Gaetano Mendola <mendola@bigfoot.com>; +Cc: pgsql-admin
Why would you want to cast that to text, if your field is a varchar? I
wouldn't think you would have to cast it at all, or if you do, cast it
to a varchar.
Curious,
WIll
On Sat, 2003-02-22 at 10:55, Gaetano Mendola wrote:
> Hi all,
>
> why in Postgresql 7.3.2 in a select like:
>
> SELECT *
> FROM user_login
> WHERE login = 'FOO'::text;
>
> and login is a VARCHAR the index on login
> is not used anymore ?
>
>
> Ciao
> Gaetano
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: index not used in ( varchar = text )
@ 2003-02-23 19:45 Gaetano Mendola <mendola@bigfoot.com>
parent: Will LaShell <will@lashell.net>
0 siblings, 1 reply; 6+ messages in thread
From: Gaetano Mendola @ 2003-02-23 19:45 UTC (permalink / raw)
To: pgsql-admin
----- Original Message -----
From: "Will LaShell" <will@lashell.net>
Newsgroups: comp.databases.postgresql.admin
Sent: Sunday, February 23, 2003 7:02 PM
Subject: Re: index not used in ( varchar = text )
> Why would you want to cast that to text, if your field is a varchar? I
> wouldn't think you would have to cast it at all, or if you do, cast it
> to a varchar.
>
> Curious,
>
> WIll
Of course that example was a semplification of a real
situation:
..........
my_login ALIAS FOR $1;
SELECT *
FROM user_login
WHERE login = my_login;
..................
and $1 is of type TEXT.
I had the same function on Postgres 7.2.3 and
was working correctly.
Ciao
Gaetano
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: index not used in ( varchar = text )
@ 2003-02-24 01:51 Tom Lane <tgl@sss.pgh.pa.us>
parent: Gaetano Mendola <mendola@bigfoot.com>
0 siblings, 1 reply; 6+ messages in thread
From: Tom Lane @ 2003-02-24 01:51 UTC (permalink / raw)
To: Gaetano Mendola <mendola@bigfoot.com>; +Cc: pgsql-admin
"Gaetano Mendola" <mendola@bigfoot.com> writes:
>> Why would you want to cast that to text, if your field is a varchar?
> Of course that example was a semplification of a real
> situation:
> ..........
> my_login ALIAS FOR $1;
> SELECT *
> FROM user_login
> WHERE login = my_login;
> and $1 is of type TEXT.
So declare it as VARCHAR. Or cast it to varchar. You need to get rid
of the datatype ambiguity. "text = text" is a different operator from
"varchar = varchar".
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: index not used in ( varchar = text )
@ 2003-02-24 08:41 Gaetano Mendola <mendola@bigfoot.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 6+ messages in thread
From: Gaetano Mendola @ 2003-02-24 08:41 UTC (permalink / raw)
To: pgsql-admin
----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
Newsgroups: comp.databases.postgresql.admin
Sent: Monday, February 24, 2003 2:57 AM
Subject: Re: index not used in ( varchar = text )
> "Gaetano Mendola" <mendola@bigfoot.com> writes:
> >> Why would you want to cast that to text, if your field is a varchar?
>
> > Of course that example was a semplification of a real
> > situation:
> > ..........
> > my_login ALIAS FOR $1;
>
> > SELECT *
> > FROM user_login
> > WHERE login = my_login;
>
> > and $1 is of type TEXT.
>
> So declare it as VARCHAR. Or cast it to varchar.
I did, and fortunatelly I found this behaviour before
to upgrade the production database.
> You need to get rid
> of the datatype ambiguity. "text = text" is a different operator from
> "varchar = varchar".
Yes I agree but was not like this in the Postgres 7.2.X version
Ciao
Gaetano.
html
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: index not used in ( varchar = text )
@ 2003-02-24 14:35 Tom Lane <tgl@sss.pgh.pa.us>
parent: Gaetano Mendola <mendola@bigfoot.com>
0 siblings, 0 replies; 6+ messages in thread
From: Tom Lane @ 2003-02-24 14:35 UTC (permalink / raw)
To: Gaetano Mendola <mendola@bigfoot.com>; +Cc: pgsql-admin
"Gaetano Mendola" <mendola@bigfoot.com> writes:
>> You need to get rid
>> of the datatype ambiguity. "text = text" is a different operator from
>> "varchar = varchar".
> Yes I agree but was not like this in the Postgres 7.2.X version
That was a bug, or at least a horridly misdesigned behavior. The
operator chosen by the parser is "text = text" (because text is the
preferred datatype in the string class). Leaving aside any issues
about whether the parser's choice is correct, it is surely no business
of the planner to replace that choice with "varchar = varchar" ---
but that's what it was doing. The folly of this idea can be seen by
realizing that the same code would equally happily replace it with
"char = char", which has distinctly different semantics.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2003-02-24 14:35 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-02-22 17:55 index not used in ( varchar = text ) Gaetano Mendola <mendola@bigfoot.com>
2003-02-23 18:07 ` Will LaShell <will@lashell.net>
2003-02-23 19:45 ` Gaetano Mendola <mendola@bigfoot.com>
2003-02-24 01:51 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-02-24 08:41 ` Gaetano Mendola <mendola@bigfoot.com>
2003-02-24 14:35 ` Tom Lane <tgl@sss.pgh.pa.us>
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