Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WVkWu-0005Ji-GE for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Apr 2014 16:30:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WVkWt-0007ON-7R for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Apr 2014 16:30:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WVSR6-0003eG-Tb for pgsql-bugs@postgresql.org; Wed, 02 Apr 2014 21:11:04 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WVSR4-0004fn-Cp for pgsql-bugs@postgresql.org; Wed, 02 Apr 2014 21:11:04 +0000 MIME-Version: 1.0 Subject: BUG #9833: daterange is not utilizing index correctly To: pgsql-bugs@postgresql.org From: shaharhd@gmail.com Date: Wed, 02 Apr 2014 21:10:18 +0000 Message-ID: <20140402211018.309.99248@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 9833 Logged by: Shahar Hadas Email address: shaharhd@gmail.com PostgreSQL version: 9.3.3 Operating system: Mac OSX - Postgres.app Description: Simple table which has a user_birthday field with a type of date (can be NULL value) there's an index (btree) defined on that field, with the rule of NOT user_birthday IS NULL. compare the following queries: explain analyze SELECT * FROM users WHERE user_birthday <@ daterange('[1978-07-15,1983-03-01)') explain analyze SELECT * FROM users WHERE user_birthday BETWEEN '1978-07-15'::date AND '1983-03-01'::date at first glance both should have the same execution plan, but for some reason, here are the results: "Seq Scan on users (cost=0.00..52314.25 rows=11101 width=241) (actual time=0.014..478.983 rows=208886 loops=1)" " Filter: (user_birthday <@ '[1978-07-15,1983-03-01)'::daterange)" " Rows Removed by Filter: 901214" "Total runtime: 489.584 ms" "Bitmap Heap Scan on users (cost=4468.01..46060.53 rows=210301 width=241) (actual time=57.104..489.785 rows=209019 loops=1)" " Recheck Cond: ((user_birthday >= '1978-07-15'::date) AND (user_birthday <= '1983-03-01'::date))" " Rows Removed by Index Recheck: 611375" " -> Bitmap Index Scan on ix_users_birthday (cost=0.00..4415.44 rows=210301 width=0) (actual time=54.621..54.621 rows=209019 loops=1)" " Index Cond: ((user_birthday >= '1978-07-15'::date) AND (user_birthday <= '1983-03-01'::date))" "Total runtime: 500.983 ms" as you can see, the <@ daterange is not utilizing the existing index, while the between does. (note that the actual use case for this rule is in a more complex query, which doesn't result in the Recheck Cond and Bitmap Heap scan) Is this a bug? or how the daterange was designed to function? -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs