pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Katherine Stoovs <ambrosiac@nedsenta.nl>
To: pgsql-hackers@postgresql.org
To: pgsql-performance@postgresql.org
Subject: tuning seqscan costs
Date: Wed, 19 Oct 2005 14:51:55 +0000 (UTC)
Message-ID: <dj5gjc$q0g$1@news.host.net> (raw)

I want to correlate two index rows of different tables to find an
offset so that

table1.value = table2.value AND table1.id = table2.id + offset

is true for a maximum number of rows.

To achieve this, I have the two tables and a table with possible
offset values and execute a query:

SELECT value,(SELECT COUNT(*) FROM table1,table2
                              WHERE table1.value = table2.value AND
                                    table1.id = table2.id + offset)
             AS matches FROM offsets ORDER BY matches;

The query is very inefficient, however, because the planner doesn't
use my indexes and executes seqscans instead. I can get it to execute
fast by setting ENABLE_SEQSCAN to OFF, but I have read this will make
the performance bad on other query types so I want to know how to
tweak the planner costs or possibly other stats so the planner will
plan the query correctly and use index scans. There must be something
wrong in the planning parameters after all if a plan that is slower by
a factor of tens or hundreds becomes estimated better than the fast
variant.

I have already issued ANALYZE commands on the tables.

Thanks for your help,
Katherine Stoovs



view thread (3+ messages)  latest in thread

Message-ID: <dj5gjc$q0g$1@news.host.net>
Permalink:  ../dj5gjc$q0g$1@news.host.net/
Also on:    postgresql.org/message-id/dj5gjc$q0g$1@news.host.net

 · 

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: ambrosiac@nedsenta.nl, pgsql-hackers@postgresql.org
  Subject: Re: tuning seqscan costs
  In-Reply-To: <dj5gjc$q0g$1@news.host.net>

* 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