pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #5705: btree_gist: Index on inet changes query result
7+ messages / 5 participants
[nested] [flat]

* BUG #5705: btree_gist: Index on inet changes query result
@ 2010-10-11 20:55 Andreas Karlsson <andreas@proxel.se>
  2010-10-11 23:50 ` Re: BUG #5705: btree_gist: Index on inet changes query result Tom Lane <tgl@sss.pgh.pa.us>
  2011-02-26 07:10 ` Re: BUG #5705: btree_gist: Index on inet changes query result Bruce Momjian <bruce@momjian.us>
  0 siblings, 2 replies; 7+ messages in thread

From: Andreas Karlsson @ 2010-10-11 20:55 UTC (permalink / raw)
  To: pgsql-bugs


The following bug has been logged online:

Bug reference:      5705
Logged by:          Andreas Karlsson
Email address:      andreas@proxel.se
PostgreSQL version: 9.1
Operating system:   Linux
Description:        btree_gist: Index on inet changes query result
Details: 

Hi,

I was looking at the code to see how one would improve indexing of the inet
types and saw an inconsistency between the compressed format
(gbt_inet_compress) and how network_cmp_internal works. The btree_gist
module ignores the netmask.

This means that while the operator thinks 1.255.255.200/8 is smaller than
1.0.0.0 the GiST index thinks the opposite.

An example for how to reproduce the bug:

-- Demostrate that I did not get the operator wrong. :)
SELECT '1.255.255.200/8'::inet < '1.0.0.0'::inet;
 ?column?
----------
 t
(1 row)

-- Create and populate table
CREATE TABLE inet_test (a inet);
INSERT INTO inet_test VALUES ('1.255.255.200/8');


-- Without index
SELECT * FROM inet_test WHERE a < '1.0.0.0'::inet;
        a        
-----------------
 1.255.255.200/8
(1 row)

EXPLAIN SELECT * FROM inet_test WHERE a < '1.0.0.0'::inet;
                         QUERY PLAN
-------------------------------------------------------------
 Seq Scan on inet_test  (cost=0.00..26.38 rows=437 width=32)
   Filter: (a < '1.0.0.0'::inet)
(2 rows)

-- With index
CREATE INDEX inet_test_idx ON inet_test USING gist (a);
SET enable_seqscan = false;

SELECT * FROM inet_test WHERE a < '1.0.0.0'::inet;
 a
---
(0 rows)

EXPLAIN SELECT * FROM inet_test WHERE a < '1.0.0.0'::inet;
                                   QUERY PLAN
----------------------------------------------------------------------------
----
 Index Scan using inet_test_idx on inet_test  (cost=0.00..8.27 rows=1
width=32)
   Index Cond: (a < '1.0.0.0'::inet)
(2 rows)

-- With btree index
DROP INDEX inet_test_idx;
CREATE INDEX inet_test_btree_idx ON inet_test USING btree (a);
SELECT * FROM inet_test WHERE a < '1.0.0.0'::inet;
        a        
-----------------
 1.255.255.200/8
(1 row)

EXPLAIN SELECT * FROM inet_test WHERE a < '1.0.0.0'::inet;
                                   QUERY PLAN                               
   
----------------------------------------------------------------------------
----
 Index Scan using inet_test_btree_idx on inet_test  (cost=0.00..8.27 rows=1
width=32)
   Index Cond: (a < '1.0.0.0'::inet)
(2 rows)



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

* Re: BUG #5705: btree_gist: Index on inet changes query result
  2010-10-11 20:55 BUG #5705: btree_gist: Index on inet changes query result Andreas Karlsson <andreas@proxel.se>
@ 2010-10-11 23:50 ` Tom Lane <tgl@sss.pgh.pa.us>
  2010-10-19 20:57   ` Re: BUG #5705: btree_gist: Index on inet changes query result Robert Haas <robertmhaas@gmail.com>
  1 sibling, 1 reply; 7+ messages in thread

From: Tom Lane @ 2010-10-11 23:50 UTC (permalink / raw)
  To: Andreas Karlsson <andreas@proxel.se>; +Cc: pgsql-bugs

"Andreas Karlsson" <andreas@proxel.se> writes:
> I was looking at the code to see how one would improve indexing of the inet
> types and saw an inconsistency between the compressed format
> (gbt_inet_compress) and how network_cmp_internal works. The btree_gist
> module ignores the netmask.

Well, actually the btree_gist implementation for inet is a completely
broken piece of junk: it thinks that convert_network_to_scalar is 100%
trustworthy and can be used as a substitute for the real comparison
functions, which isn't even approximately true.  I'm not sure why
Teodor implemented it like that instead of using the type's real
comparison functions, but it's pretty much useless if you want the
same sort order that the type itself defines.

			regards, tom lane



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

* Re: BUG #5705: btree_gist: Index on inet changes query result
  2010-10-11 20:55 BUG #5705: btree_gist: Index on inet changes query result Andreas Karlsson <andreas@proxel.se>
  2010-10-11 23:50 ` Re: BUG #5705: btree_gist: Index on inet changes query result Tom Lane <tgl@sss.pgh.pa.us>
@ 2010-10-19 20:57   ` Robert Haas <robertmhaas@gmail.com>
  2010-10-19 22:22     ` Re: BUG #5705: btree_gist: Index on inet changes query result Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Robert Haas @ 2010-10-19 20:57 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Andreas Karlsson <andreas@proxel.se>; pgsql-bugs

On Mon, Oct 11, 2010 at 7:50 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "Andreas Karlsson" <andreas@proxel.se> writes:
>> I was looking at the code to see how one would improve indexing of the inet
>> types and saw an inconsistency between the compressed format
>> (gbt_inet_compress) and how network_cmp_internal works. The btree_gist
>> module ignores the netmask.
>
> Well, actually the btree_gist implementation for inet is a completely
> broken piece of junk: it thinks that convert_network_to_scalar is 100%
> trustworthy and can be used as a substitute for the real comparison
> functions, which isn't even approximately true.  I'm not sure why
> Teodor implemented it like that instead of using the type's real
> comparison functions, but it's pretty much useless if you want the
> same sort order that the type itself defines.

Are you planning to fix this?

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



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

* Re: BUG #5705: btree_gist: Index on inet changes query result
  2010-10-11 20:55 BUG #5705: btree_gist: Index on inet changes query result Andreas Karlsson <andreas@proxel.se>
  2010-10-11 23:50 ` Re: BUG #5705: btree_gist: Index on inet changes query result Tom Lane <tgl@sss.pgh.pa.us>
  2010-10-19 20:57   ` Re: BUG #5705: btree_gist: Index on inet changes query result Robert Haas <robertmhaas@gmail.com>
@ 2010-10-19 22:22     ` Tom Lane <tgl@sss.pgh.pa.us>
  2010-10-21 21:49       ` Re: BUG #5705: btree_gist: Index on inet changes query result andreas <andreas@proxel.se>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2010-10-19 22:22 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Andreas Karlsson <andreas@proxel.se>; pgsql-bugs

Robert Haas <robertmhaas@gmail.com> writes:
> On Mon, Oct 11, 2010 at 7:50 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Well, actually the btree_gist implementation for inet is a completely
>> broken piece of junk: it thinks that convert_network_to_scalar is 100%
>> trustworthy and can be used as a substitute for the real comparison
>> functions, which isn't even approximately true.

> Are you planning to fix this?

No.  I don't understand why Teodor did it like that, so I'm not going
to try to change it.  I'd be willing to take responsibility for ripping
out btree_gist's inet support altogether ...

			regards, tom lane



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

* Re: BUG #5705: btree_gist: Index on inet changes query result
  2010-10-11 20:55 BUG #5705: btree_gist: Index on inet changes query result Andreas Karlsson <andreas@proxel.se>
  2010-10-11 23:50 ` Re: BUG #5705: btree_gist: Index on inet changes query result Tom Lane <tgl@sss.pgh.pa.us>
  2010-10-19 20:57   ` Re: BUG #5705: btree_gist: Index on inet changes query result Robert Haas <robertmhaas@gmail.com>
  2010-10-19 22:22     ` Re: BUG #5705: btree_gist: Index on inet changes query result Tom Lane <tgl@sss.pgh.pa.us>
@ 2010-10-21 21:49       ` andreas <andreas@proxel.se>
  2011-03-05 20:14         ` Re: BUG #5705: btree_gist: Index on inet changes query result Bruce Momjian <bruce@momjian.us>
  0 siblings, 1 reply; 7+ messages in thread

From: andreas @ 2010-10-21 21:49 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Robert Haas <robertmhaas@gmail.com>; pgsql-bugs

On Tue, 2010-10-19 at 18:22 -0400, Tom Lane wrote:
> Robert Haas <robertmhaas@gmail.com> writes:
> > On Mon, Oct 11, 2010 at 7:50 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >> Well, actually the btree_gist implementation for inet is a completely
> >> broken piece of junk: it thinks that convert_network_to_scalar is 100%
> >> trustworthy and can be used as a substitute for the real comparison
> >> functions, which isn't even approximately true.
> 
> > Are you planning to fix this?
> 
> No.  I don't understand why Teodor did it like that, so I'm not going
> to try to change it.  I'd be willing to take responsibility for ripping
> out btree_gist's inet support altogether ...
> 
> 			regards, tom lane

That is the reason why I just reported it instead of trying to fix it
myself first. Since I could not understand why it was done like that, I
did not feel like fixing it.

Best regards,
Andreas Karlsson





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

* Re: BUG #5705: btree_gist: Index on inet changes query result
  2010-10-11 20:55 BUG #5705: btree_gist: Index on inet changes query result Andreas Karlsson <andreas@proxel.se>
  2010-10-11 23:50 ` Re: BUG #5705: btree_gist: Index on inet changes query result Tom Lane <tgl@sss.pgh.pa.us>
  2010-10-19 20:57   ` Re: BUG #5705: btree_gist: Index on inet changes query result Robert Haas <robertmhaas@gmail.com>
  2010-10-19 22:22     ` Re: BUG #5705: btree_gist: Index on inet changes query result Tom Lane <tgl@sss.pgh.pa.us>
  2010-10-21 21:49       ` Re: BUG #5705: btree_gist: Index on inet changes query result andreas <andreas@proxel.se>
@ 2011-03-05 20:14         ` Bruce Momjian <bruce@momjian.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Bruce Momjian @ 2011-03-05 20:14 UTC (permalink / raw)
  To: andreas <andreas@proxel.se>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Robert Haas <robertmhaas@gmail.com>; pgsql-bugs


This is currently a TODO so at least we are tracking it.

---------------------------------------------------------------------------

andreas wrote:
> On Tue, 2010-10-19 at 18:22 -0400, Tom Lane wrote:
> > Robert Haas <robertmhaas@gmail.com> writes:
> > > On Mon, Oct 11, 2010 at 7:50 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> > >> Well, actually the btree_gist implementation for inet is a completely
> > >> broken piece of junk: it thinks that convert_network_to_scalar is 100%
> > >> trustworthy and can be used as a substitute for the real comparison
> > >> functions, which isn't even approximately true.
> > 
> > > Are you planning to fix this?
> > 
> > No.  I don't understand why Teodor did it like that, so I'm not going
> > to try to change it.  I'd be willing to take responsibility for ripping
> > out btree_gist's inet support altogether ...
> > 
> > 			regards, tom lane
> 
> That is the reason why I just reported it instead of trying to fix it
> myself first. Since I could not understand why it was done like that, I
> did not feel like fixing it.
> 
> Best regards,
> Andreas Karlsson
> 
> 
> 
> -- 
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +



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

* Re: BUG #5705: btree_gist: Index on inet changes query result
  2010-10-11 20:55 BUG #5705: btree_gist: Index on inet changes query result Andreas Karlsson <andreas@proxel.se>
@ 2011-02-26 07:10 ` Bruce Momjian <bruce@momjian.us>
  1 sibling, 0 replies; 7+ messages in thread

From: Bruce Momjian @ 2011-02-26 07:10 UTC (permalink / raw)
  To: Andreas Karlsson <andreas@proxel.se>; +Cc: pgsql-bugs; Teodor Sigaev <teodor@sigaev.ru>


Teodor, would you please comment on this bug after reading the entire
thread which includes comments from other developers?

	http://archives.postgresql.org/pgsql-bugs/2010-10/msg00099.php

Thanks.

---------------------------------------------------------------------------

Andreas Karlsson wrote:
> 
> The following bug has been logged online:
> 
> Bug reference:      5705
> Logged by:          Andreas Karlsson
> Email address:      andreas@proxel.se
> PostgreSQL version: 9.1
> Operating system:   Linux
> Description:        btree_gist: Index on inet changes query result
> Details: 
> 
> Hi,
> 
> I was looking at the code to see how one would improve indexing of the inet
> types and saw an inconsistency between the compressed format
> (gbt_inet_compress) and how network_cmp_internal works. The btree_gist
> module ignores the netmask.
> 
> This means that while the operator thinks 1.255.255.200/8 is smaller than
> 1.0.0.0 the GiST index thinks the opposite.
> 
> An example for how to reproduce the bug:
> 
> -- Demostrate that I did not get the operator wrong. :)
> SELECT '1.255.255.200/8'::inet < '1.0.0.0'::inet;
>  ?column?
> ----------
>  t
> (1 row)
> 
> -- Create and populate table
> CREATE TABLE inet_test (a inet);
> INSERT INTO inet_test VALUES ('1.255.255.200/8');
> 
> 
> -- Without index
> SELECT * FROM inet_test WHERE a < '1.0.0.0'::inet;
>         a        
> -----------------
>  1.255.255.200/8
> (1 row)
> 
> EXPLAIN SELECT * FROM inet_test WHERE a < '1.0.0.0'::inet;
>                          QUERY PLAN
> -------------------------------------------------------------
>  Seq Scan on inet_test  (cost=0.00..26.38 rows=437 width=32)
>    Filter: (a < '1.0.0.0'::inet)
> (2 rows)
> 
> -- With index
> CREATE INDEX inet_test_idx ON inet_test USING gist (a);
> SET enable_seqscan = false;
> 
> SELECT * FROM inet_test WHERE a < '1.0.0.0'::inet;
>  a
> ---
> (0 rows)
> 
> EXPLAIN SELECT * FROM inet_test WHERE a < '1.0.0.0'::inet;
>                                    QUERY PLAN
> ----------------------------------------------------------------------------
> ----
>  Index Scan using inet_test_idx on inet_test  (cost=0.00..8.27 rows=1
> width=32)
>    Index Cond: (a < '1.0.0.0'::inet)
> (2 rows)
> 
> -- With btree index
> DROP INDEX inet_test_idx;
> CREATE INDEX inet_test_btree_idx ON inet_test USING btree (a);
> SELECT * FROM inet_test WHERE a < '1.0.0.0'::inet;
>         a        
> -----------------
>  1.255.255.200/8
> (1 row)
> 
> EXPLAIN SELECT * FROM inet_test WHERE a < '1.0.0.0'::inet;
>                                    QUERY PLAN                               
>    
> ----------------------------------------------------------------------------
> ----
>  Index Scan using inet_test_btree_idx on inet_test  (cost=0.00..8.27 rows=1
> width=32)
>    Index Cond: (a < '1.0.0.0'::inet)
> (2 rows)
> 
> -- 
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +



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


end of thread, other threads:[~2011-03-05 20:14 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-10-11 20:55 BUG #5705: btree_gist: Index on inet changes query result Andreas Karlsson <andreas@proxel.se>
2010-10-11 23:50 ` Tom Lane <tgl@sss.pgh.pa.us>
2010-10-19 20:57   ` Robert Haas <robertmhaas@gmail.com>
2010-10-19 22:22     ` Tom Lane <tgl@sss.pgh.pa.us>
2010-10-21 21:49       ` andreas <andreas@proxel.se>
2011-03-05 20:14         ` Bruce Momjian <bruce@momjian.us>
2011-02-26 07:10 ` Bruce Momjian <bruce@momjian.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