dbTalk Databases Forums  

[BUGS] BUG #1487: Index problem

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #1487: Index problem in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tom Yeh
 
Posts: n/a

Default [BUGS] BUG #1487: Index problem - 02-20-2005 , 11:55 PM







The following bug has been logged online:

Bug reference: 1487
Logged by: Tom Yeh
Email address: tom_m_yeh (AT) yahoo (DOT) com
PostgreSQL version: 8.0.1
Operating system: Windows XP
Description: Index problem
Details:

I created an index for a table, say Entity, on a field, say id.

Then, the follwoing two SQL has different result:

select * from "Entity" e where e.id = '1000'

and

select * from "Entity" e where e.id like '1000'

(The later uses sequential scan. BTW, while 7.4.x uses index why 8.0 behave
worse?)

Once I re-index it, the problem is gone. However, the problem comes back
randomly if I change some id.

The above can be replicated by using pgAdmin III only.

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Reply With Quote
  #2  
Old   
Richard Huxton
 
Posts: n/a

Default Re: [BUGS] BUG #1487: Index problem - 02-21-2005 , 09:40 AM






Tom Yeh wrote:
Quote:
I created an index for a table, say Entity, on a field, say id.

Then, the follwoing two SQL has different result:

select * from "Entity" e where e.id = '1000'
select * from "Entity" e where e.id like '1000'
What is the definition of "Entity"?
How many rows are there in the table?
How many match '1000'?
Are your statistics up to date?
Are you happy that you are gathering enough statistics values for the
"id" column?
Do you understand the issues with using LIKE and non-C locales?

Quote:
(The later uses sequential scan. BTW, while 7.4.x uses index why 8.0 behave
worse?)
You don't say how the EXPLAIN ANALYSE for each is different.

Quote:
Once I re-index it, the problem is gone. However, the problem comes back
randomly if I change some id.
By "randomly" do you mean it switches plans depending on the value you
match against, or that you can repeat the same query twice and it uses
different plans?

Quote:
The above can be replicated by using pgAdmin III only.
Are you saying it doesn't do this from psql?

If you're not convinced this is an actual bug in PostgreSQL's planner,
it might be better to post details to the performance or sql lists where
there are more people to help answer.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
  #3  
Old   
Dave Page
 
Posts: n/a

Default Re: [BUGS] BUG #1487: Index problem - 02-21-2005 , 10:06 AM



=20

Quote:
-----Original Message-----
From: pgsql-bugs-owner (AT) postgresql (DOT) org=20
[mailtogsql-bugs-owner (AT) postgresql (DOT) org] On Behalf Of Richard Huxton
Sent: 21 February 2005 15:37
To: Tom Yeh
Cc: pgsql-bugs (AT) postgresql (DOT) org
Subject: Re: [BUGS] BUG #1487: Index problem
=20
The above can be replicated by using pgAdmin III only.
=20
Are you saying it doesn't do this from psql?
pgAdmin uses libpq, just as psql does, so I cannot imagine why this
would be the case. pgAdmin also does not do anything to try to affect
query plans in any way.

Regards, Dave.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
  #4  
Old   
Richard Huxton
 
Posts: n/a

Default Re: [BUGS] BUG #1487: Index problem - 02-21-2005 , 10:15 AM



Dave Page wrote:
Quote:
-----Original Message-----
From: pgsql-bugs-owner (AT) postgresql (DOT) org
[mailtogsql-bugs-owner (AT) postgresql (DOT) org] On Behalf Of Richard Huxton
Sent: 21 February 2005 15:37
To: Tom Yeh
Cc: pgsql-bugs (AT) postgresql (DOT) org
Subject: Re: [BUGS] BUG #1487: Index problem


The above can be replicated by using pgAdmin III only.

Are you saying it doesn't do this from psql?


pgAdmin uses libpq, just as psql does, so I cannot imagine why this
would be the case. pgAdmin also does not do anything to try to affect
query plans in any way.
Could it set the encoding/locale differently to psql (on the same machine)?

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


Reply With Quote
  #5  
Old   
Dave Page
 
Posts: n/a

Default Re: [BUGS] BUG #1487: Index problem - 02-21-2005 , 10:21 AM



=20

Quote:
-----Original Message-----
From: Richard Huxton [mailto:dev (AT) archonet (DOT) com]=20
Sent: 21 February 2005 16:13
To: Dave Page
Cc: Tom Yeh; pgsql-bugs (AT) postgresql (DOT) org
Subject: Re: [BUGS] BUG #1487: Index problem
=20
pgAdmin uses libpq, just as psql does, so I cannot imagine why this
would be the case. pgAdmin also does not do anything to try=20
to affect
query plans in any way.
=20
Could it set the encoding/locale differently to psql (on the=20
same machine)?
Good point, yes - it will try to set the encoding to unicode if it can.

/D

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Reply With Quote
  #6  
Old   
Richard Huxton
 
Posts: n/a

Default Re: [BUGS] BUG #1487: Index problem - 02-21-2005 , 11:16 AM



Tom M. Yeh wrote:
Quote:
Yes, it really depends on Locale. If I created a
database with Locale = C, the problem won't happen (at
least so far). BTW, I forgot to mention I tested with
some Chinese and Japanese characters.

However, it raises another issue why a wrong Locale
would damage index? It shall only affect records with
wrong conversion, not something like '1000'.
Search the list archives for LIKE and locale - different locales have
different sorting rules. Setting locale=C makes everything simple.

With 8.0 you can define your own operator classes to tell PG it can use
an index (see ch 11.6 of the manuals). I think there are examples in the
mailing-list archives.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Reply With Quote
  #7  
Old   
Tom M. Yeh
 
Posts: n/a

Default Re: [BUGS] BUG #1487: Index problem - 02-22-2005 , 11:41 PM



Yes, it really depends on Locale. If I created a
database with Locale = C, the problem won't happen (at
least so far). BTW, I forgot to mention I tested with
some Chinese and Japanese characters.

However, it raises another issue why a wrong Locale
would damage index? It shall only affect records with
wrong conversion, not something like '1000'.

The real environment in my program is J2EE+JDBC. I
simply used pgAdmin to demonstrate the problem (not
caused by JDBC or so).

Though Locale C solved the problem, LIKE 'prefix%'
still uses Seq Scan. It is a job to change hundreds
(if not thousands SQL) to use BETWEEN/AND instead. Any
suggestion?

-----Original Message-----
From: Dave Page [mailto:dpage (AT) vale-housing (DOT) co.uk]
Sent: Tuesday, February 22, 2005 12:19 AM
To: Richard Huxton
Cc: Tom Yeh; pgsql-bugs (AT) postgresql (DOT) org
Subject: RE: [BUGS] BUG #1487: Index problem




Quote:
-----Original Message-----
From: Richard Huxton [mailto:dev (AT) archonet (DOT) com]
Sent: 21 February 2005 16:13
To: Dave Page
Cc: Tom Yeh; pgsql-bugs (AT) postgresql (DOT) org
Subject: Re: [BUGS] BUG #1487: Index problem

pgAdmin uses libpq, just as psql does, so I cannot
imagine why this
would be the case. pgAdmin also does not do
anything to try
to affect
query plans in any way.

Could it set the encoding/locale differently to psql
(on the
same machine)?
Good point, yes - it will try to set the encoding to
unicode if it can.

/D




__________________________________
Do you Yahoo!?
The all-new My Yahoo! - Get yours free!
http://my.yahoo.com



---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.