pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Liviu Mirea-Ghiban <liviu.mirea@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Slow query using the Cube contrib module.
Date: Sun, 25 Jul 2010 13:32:49 +0300
Message-ID: <4C4C12D1.70601@gmail.com> (raw)

  Hello,

I have a simple table which has a cube column and a cube GiST index. The 
column contains 3-dimensional points (not cubes or intervals). The 
problem is that I'm getting very slow queries when I'm using the index. 
The table has about 130,000 rows and is full-vacuumed after any 
updates/inserts (it is updated only once every 24 hours).


Table definition:
CREATE TABLE picof.photo_colors
(
   photo_id integer NOT NULL,
   color_percent real NOT NULL,
   lab_color picof.cube NOT NULL
)
WITH (
   OIDS=FALSE
);

CREATE INDEX photo_colors_index
   ON picof.photo_colors
   USING gist
   (lab_color);


My query:
SELECT photo_id FROM photo_colors
WHERE lab_color <@ cube_enlarge('0, 0, 0', 10, 3)


Explain analyze:
"Bitmap Heap Scan on photo_colors  (cost=13.40..421.55 rows=135 width=4) 
(actual time=7.958..15.493 rows=14313 loops=1)"
"  Recheck Cond: (lab_color <@ '(-10, -10, -10),(10, 10, 10)'::cube)"
"  ->  Bitmap Index Scan on photo_colors_index  (cost=0.00..13.36 
rows=135 width=0) (actual time=7.556..7.556 rows=14313 loops=1)"
"        Index Cond: (lab_color <@ '(-10, -10, -10),(10, 10, 10)'::cube)"
"Total runtime: 16.849 ms"
(Executed in PostgreSQL 8.4.4 on Windows and CentOS - same query plan)


Now, while it might not seem much, this is part of a bigger query in 
which several such subqueries are being joined. The cost really adds up.

My question is: Why is it doing a Bitmap Heap Scan / Recheck Cond? I've 
executed dozens of such queries and not once did the rechecking remove 
any rows. Is there any way to disable it, or do you have any other 
suggestions for optimizations (because I'm all out of ideas)?

Thank you in advance!

---
Liviu Mirea



view thread (3+ messages)  latest in thread

Message-ID: <4C4C12D1.70601@gmail.com>
Permalink:  ../4C4C12D1.70601@gmail.com/
Also on:    postgresql.org/message-id/4C4C12D1.70601@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: liviu.mirea@gmail.com
  Subject: Re: Slow query using the Cube contrib module.
  In-Reply-To: <4C4C12D1.70601@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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