pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
accessing primary key slower than accessing non primary key???
2+ messages / 2 participants
[nested] [flat]

* accessing primary key slower than accessing non primary key???
@ 2003-02-13 13:59  HK <harikrishnan@midascomm.com>
  0 siblings, 1 reply; 2+ messages in thread

From: HK @ 2003-02-13 13:59 UTC (permalink / raw)
  To: pgsql-novice@postgresql.org

hi,
I am using postgresql 7.1.3 under RH linux 7.2
For sake of comparison of speeds i am doing a small experiment.
I am having a table with 20 columns (1 col with bigint as primary key)
the size of a record is 300 bytes.
On retrieving records with select query with where clause accessing a 
primary key and a non primary key the times are as follows


	      time in ms per query retrieval
		py key   non py key
		------   -----------
2000            15.8     15.7
10000           71.2     70.7
25000           174      173.5 
100000          4319     3417

As u see the non primary key retrieval is faster. AFAIK accessing primary 
key should be faster. Can anybody throw light on why is this anamoly.

I use libpq with blocking execution of queries.
I ran this test with there being no other load in the system.

TIA.

--------
regards,
hari
      __
     / /    __  _  _  _  _ __  __         -o) 
    / /__  / / / \\// //_// \\ \\/ /         /\\\\  Making things happen
   /____/ /_/ /_/\\/ /___/  /_/\\_\\        _\\_v-  





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: accessing primary key slower than accessing non primary key???
@ 2003-02-13 15:45  Tom Lane <tgl@sss.pgh.pa.us>
  parent: HK <harikrishnan@midascomm.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2003-02-13 15:45 UTC (permalink / raw)
  To: HK <harikrishnan@midascomm.com>; +Cc: pgsql-novice@postgresql.org

HK <harikrishnan@midascomm.com> writes:
> 	      time in ms per query retrieval
> 		py key   non py key
> 		------   -----------
> 2000            15.8     15.7
> 10000           71.2     70.7
> 25000           174      173.5 
> 100000          4319     3417

> As u see the non primary key retrieval is faster. AFAIK accessing primary 
> key should be faster. Can anybody throw light on why is this anamoly.

There's nothing magic about primary keys in Postgres; I'd expect the
results to come out the same.

The first three of these look like they're indeed the same, to within
measurement error.  Not sure about the last one; perhaps you had some
effect of physical order in the table agreeing with the ordering of the
non-primary key?

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2003-02-13 15:45 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-02-13 13:59 accessing primary key slower than accessing non primary key??? HK <harikrishnan@midascomm.com>
2003-02-13 15:45 ` Tom Lane <tgl@sss.pgh.pa.us>

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