Re: count(*) performance improvement ideas - Mailing list pgsql-hackers

From Stephen Denne
Subject Re: count(*) performance improvement ideas
Date
Msg-id F0238EBA67824444BC1CB4700960CB48051D6069@dmpeints002.isotach.com
Whole thread Raw
In response to Re: count(*) performance improvement ideas  (PFC <lists@peufeu.com>)
Responses Re: count(*) performance improvement ideas  (PFC <lists@peufeu.com>)
List pgsql-hackers
PFC wrote:
> Let's try this quick & dirty implementation of a local 
> count-delta cache  
> using a local in-memory hashtable (ie. {}).

> CREATE OR REPLACE FUNCTION update_count( key TEXT, delta INTEGER )
>    RETURNS INTEGER
> AS $$
>      if key in GD:
>              GD[key] += delta
>      else:
>              GD[key] = delta
>      return GD[key]
> $$ LANGUAGE plpythonu;

Thanks for the code, this seems to be very much what I was looking for.

I don't know plpythonu (nor python), just read a few docs now:
"The global dictionary SD is available to store data between function calls. This variable is private static data. The
globaldictionary GD is public data, available to all Python functions within a session. Use with care."
 

Does session == transaction or connection?
I don't understand the difference between SD and GD, private and public. Where are the context boundaries?

Regards,
Stephen Denne.

Disclaimer:
At the Datamail Group we value team commitment, respect, achievement, customer focus, and courage. This email with any
attachmentsis confidential and may be subject to legal privilege.  If it is not intended for you please advise by reply
immediately,destroy it and do not copy, disclose or use it in any way. 
__________________________________________________________________ This email has been scanned by the DMZGlobal
BusinessQuality             Electronic Messaging Suite. 
Please see http://www.dmzglobal.com/dmzmessaging.htm for details.
__________________________________________________________________


pgsql-hackers by date:

Previous
From: "Stephen Denne"
Date:
Subject: Re: count(*) performance improvement ideas
Next
From: Gregory Stark
Date:
Subject: Re: How to submit a patch