Re: in C trigger function find out if column is part of primary key - Mailing list pgsql-general

From Marko Kreen
Subject Re: in C trigger function find out if column is part of primary key
Date
Msg-id 20130401072510.GA25503@gmail.com
Whole thread Raw
In response to in C trigger function find out if column is part of primary key  ("Enke, Dr., Michael" <michael.enke@wincor-nixdorf.com>)
List pgsql-general
On Mon, Apr 01, 2013 at 12:06:25AM +0200, Enke, Dr., Michael wrote:
> I have to find out if a column ( i = 0, ..., tupdesc->natts-1 ) is part of a primary key
> but for performance reasons I do not want to execute another query via SPI.
> Is this possible?

Simpler and probably even faster approach would be to do
catalog lookup via SPI and then cache the result.

The trick here is to get cache invalidation right,
so on any table change cache is refreshed.

You can use PgQ triggers as example:

  https://github.com/markokr/skytools/blob/master/sql/pgq/triggers/common.c

It implements various unrelated features, but basics are in
find_table_info() which loads cached data and relcache_reset_cb()
which invalidates.

--
marko



pgsql-general by date:

Previous
From: Jasen Betts
Date:
Subject: Re: Using varchar primary keys.
Next
From: Adrian Klaver
Date:
Subject: Re: Problem with pg_basebackup and streaming replication. (9.2.3 / win64)