Unix Technical Forum

Re: possible bug with compound index.

This is a discussion on Re: possible bug with compound index. within the Pgsql General forums, part of the PostgreSQL category; --> On Mon, 14 Feb 2005, Neil Dugan wrote: > I am using PostgreSQL 7.4.7 > I have a table ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 07:34 PM
Stephan Szabo
 
Posts: n/a
Default Re: possible bug with compound index.

On Mon, 14 Feb 2005, Neil Dugan wrote:

> I am using PostgreSQL 7.4.7
> I have a table with serveral fields two of these are a serialno
> (bigserial) and name(varchar). I have created two indexs on these
> fields.
> 1) on name
> 2) on name,serialno
> if I use the command
> 'select * from table order by name limit 1'
> everything is OK
> if I use the command
> 'select * from table order by name desc limit 1'
> everything is OK
> if I use the command
> 'select * from table order by name,serialno limit 1'
> everything is OK
> if I use the command
> 'select * from table order by name,serialno desc limit 1'
> The command is SLOW and gives back the INCORRECT data.


Without any example data and result, it's hard to say what you were
expecting or got. I'd expect the highest numbered serialno record for the
lowest sorting name from the above which is what any tests I've tried do.

Right now I believe it won't consider index usage because the ordering
asked for doesn't match either a forward ordering of the index(name,
serialno) or a reverse order (name desc, serialno desc).

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 07:34 PM
Neil Dugan
 
Posts: n/a
Default Re: possible bug with compound index.

On Sun, 2005-02-13 at 20:40 -0800, Stephan Szabo wrote:
> On Mon, 14 Feb 2005, Neil Dugan wrote:
>
> > I am using PostgreSQL 7.4.7
> > I have a table with serveral fields two of these are a serialno
> > (bigserial) and name(varchar). I have created two indexs on these
> > fields.
> > 1) on name
> > 2) on name,serialno
> > if I use the command
> > 'select * from table order by name limit 1'
> > everything is OK
> > if I use the command
> > 'select * from table order by name desc limit 1'
> > everything is OK
> > if I use the command
> > 'select * from table order by name,serialno limit 1'
> > everything is OK
> > if I use the command
> > 'select * from table order by name,serialno desc limit 1'
> > The command is SLOW and gives back the INCORRECT data.

>
> Without any example data and result, it's hard to say what you were
> expecting or got. I'd expect the highest numbered serialno record for the
> lowest sorting name from the above which is what any tests I've tried do.
>
> Right now I believe it won't consider index usage because the ordering
> asked for doesn't match either a forward ordering of the index(name,
> serialno) or a reverse order (name desc, serialno desc).


Thanks Stephan, for the hint on using desc twice.
'select * from table order by name desc,serialno desc limit 1'
does work.

I didn't realise it was separating the order into two sections, I'm
sorry if this caused any trouble for you. My mistake, bye!




---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 07:35 PM
Bruce Momjian
 
Posts: n/a
Default Re: possible bug with compound index.

Neil Dugan wrote:
> On Sun, 2005-02-13 at 20:40 -0800, Stephan Szabo wrote:
> > On Mon, 14 Feb 2005, Neil Dugan wrote:
> >
> > > I am using PostgreSQL 7.4.7
> > > I have a table with serveral fields two of these are a serialno
> > > (bigserial) and name(varchar). I have created two indexs on these
> > > fields.
> > > 1) on name
> > > 2) on name,serialno
> > > if I use the command
> > > 'select * from table order by name limit 1'
> > > everything is OK
> > > if I use the command
> > > 'select * from table order by name desc limit 1'
> > > everything is OK
> > > if I use the command
> > > 'select * from table order by name,serialno limit 1'
> > > everything is OK
> > > if I use the command
> > > 'select * from table order by name,serialno desc limit 1'
> > > The command is SLOW and gives back the INCORRECT data.

> >
> > Without any example data and result, it's hard to say what you were
> > expecting or got. I'd expect the highest numbered serialno record for the
> > lowest sorting name from the above which is what any tests I've tried do.
> >
> > Right now I believe it won't consider index usage because the ordering
> > asked for doesn't match either a forward ordering of the index(name,
> > serialno) or a reverse order (name desc, serialno desc).

>
> Thanks Stephan, for the hint on using desc twice.
> 'select * from table order by name desc,serialno desc limit 1'
> does work.
>
> I didn't realise it was separating the order into two sections, I'm
> sorry if this caused any trouble for you. My mistake, bye!


What this brings up is that we have no way to create indexes that have
mixed ascending/descending column specifications.

Should this be a TODO? I am unsure.

--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 07:35 PM
Scott Marlowe
 
Posts: n/a
Default Re: possible bug with compound index.

On Mon, 2005-02-14 at 12:55, Bruce Momjian wrote:
> Neil Dugan wrote:
> > On Sun, 2005-02-13 at 20:40 -0800, Stephan Szabo wrote:
> > > On Mon, 14 Feb 2005, Neil Dugan wrote:
> > >
> > > > I am using PostgreSQL 7.4.7
> > > > I have a table with serveral fields two of these are a serialno
> > > > (bigserial) and name(varchar). I have created two indexs on these
> > > > fields.
> > > > 1) on name
> > > > 2) on name,serialno
> > > > if I use the command
> > > > 'select * from table order by name limit 1'
> > > > everything is OK
> > > > if I use the command
> > > > 'select * from table order by name desc limit 1'
> > > > everything is OK
> > > > if I use the command
> > > > 'select * from table order by name,serialno limit 1'
> > > > everything is OK
> > > > if I use the command
> > > > 'select * from table order by name,serialno desc limit 1'
> > > > The command is SLOW and gives back the INCORRECT data.
> > >
> > > Without any example data and result, it's hard to say what you were
> > > expecting or got. I'd expect the highest numbered serialno record for the
> > > lowest sorting name from the above which is what any tests I've tried do.
> > >
> > > Right now I believe it won't consider index usage because the ordering
> > > asked for doesn't match either a forward ordering of the index(name,
> > > serialno) or a reverse order (name desc, serialno desc).

> >
> > Thanks Stephan, for the hint on using desc twice.
> > 'select * from table order by name desc,serialno desc limit 1'
> > does work.
> >
> > I didn't realise it was separating the order into two sections, I'm
> > sorry if this caused any trouble for you. My mistake, bye!

>
> What this brings up is that we have no way to create indexes that have
> mixed ascending/descending column specifications.
>
> Should this be a TODO? I am unsure.


I thought it was a todo

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:47 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com