Which query is less expensive / faster?

From: Postgres Coder <postgrescoder(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Which query is less expensive / faster?
Date: 2005-02-24 23:46:28
Message-ID: c2213f3d05022415466c2e7bdc@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

I have a couple different ways to get results out of my table
structure, but I'm unsure which way is faster or less expensive to
run:

Option 1: Query a table of 4 million rows, on 4 indexed columns. It
will return 1 row:

SELECT field1, field2, field3, field4
FROM tablea
WHERE field1 = $1 AND field2 = $2 AND field3 = $3 AND field4 = $4

Option 2: Query a table of 200,000 rows on 1 indexed column. It will
return 800 rows:

SELECT *
FROM tableb
WHERE field1 = $1

Which one is going to return results the fastest, with the least
expense to the database server?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Guy Rouillier 2005-02-24 23:49:47 Re: basic trigger using OLD not working?
Previous Message Edmund Bacon 2005-02-24 23:13:01 Re: basic trigger using OLD not working?