Re: varchar as primary key - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: varchar as primary key
Date
Msg-id 20070504214556.GC28680@svana.org
Whole thread Raw
In response to Re: varchar as primary key  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: varchar as primary key
List pgsql-general
On Fri, May 04, 2007 at 03:42:45PM -0400, Tom Lane wrote:
> It's hardly credible that you could do either strcmp or strcoll in 2 nsec
> on any run-of-the-mill hardware.  What I think is happening is that the
> compiler is aware that these are side-effect-free functions and is
> removing the calls entirely, or at least moving them out of the loops;
> these times would be credible for loops consisting only of an increment,
> test, and branch.

It's not the compiler, it's the C library. strcmp and strcoll are
defined as:

  extern int strcoll (__const char *__s1, __const char *__s2)
     __THROW __attribute_pure__ __nonnull ((1, 2));

In this context "pure" is essentially what IMMUTABLE is in postgres.

Which doesn't change the fact that strcoll is expensive.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment

pgsql-general by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: Casting to varchar
Next
From: Tom Lane
Date:
Subject: Re: Casting to varchar