Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 2677D1336FA7 for ; Sat, 26 Feb 2011 03:10:24 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 22436-04 for ; Sat, 26 Feb 2011 07:10:17 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from momjian.us (momjian.us [70.90.9.53]) by mail.postgresql.org (Postfix) with ESMTP id 080A5133616B for ; Sat, 26 Feb 2011 03:10:15 -0400 (AST) Received: (from bruce@localhost) by momjian.us (8.11.6/8.11.6) id p1Q7AD205413; Sat, 26 Feb 2011 02:10:13 -0500 (EST) From: Bruce Momjian Message-Id: <201102260710.p1Q7AD205413@momjian.us> Subject: Re: BUG #5705: btree_gist: Index on inet changes query result In-Reply-To: <201010112055.o9BKtZf7011251@wwwmaster.postgresql.org> To: Andreas Karlsson Date: Sat, 26 Feb 2011 02:10:12 -0500 (EST) CC: pgsql-bugs@postgresql.org, Teodor Sigaev X-Mailer: ELM [version 2.4ME+ PL124 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="US-ASCII" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/229 X-Sequence-Number: 29501 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 http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. +