X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5A05BD7282 for ; Thu, 24 Nov 2005 01:34:13 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 51167-04 for ; Thu, 24 Nov 2005 05:34:12 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from linda-1.paradise.net.nz (bm-1a.paradise.net.nz [203.96.152.180]) by svr1.postgresql.org (Postfix) with ESMTP id 5F547D704F for ; Thu, 24 Nov 2005 01:34:06 -0400 (AST) Received: from smtp-1.paradise.net.nz (tclsnelbe2-src-nat-1 [203.96.152.177]) by linda-1.paradise.net.nz (Paradise.net.nz) with ESMTP id <0IQG006IL24TZH@linda-1.paradise.net.nz> for pgsql-performance@postgresql.org; Thu, 24 Nov 2005 18:34:05 +1300 (NZDT) Received: from [192.168.1.11] (218-101-28-4.dsl.clear.net.nz [218.101.28.4]) by smtp-1.paradise.net.nz (Postfix) with ESMTP id BEB2011536AB; Thu, 24 Nov 2005 18:34:04 +1300 (NZDT) Date: Thu, 24 Nov 2005 18:34:03 +1300 From: Mark Kirkwood Subject: Re: Hardware/OS recommendations for large databases ( In-reply-to: To: Luke Lonergan Cc: pgsql-performance@postgresql.org, "eng@intranet.greenplum.com" Message-id: <438550CB.5020506@paradise.net.nz> MIME-version: 1.0 Content-type: multipart/mixed; boundary="Boundary_(ID_QaxGn75YzNMJHffeg0xdpg)" X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.6 (X11/20051106) References: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.261 required=5 tests=[AWL=0.261] X-Spam-Score: 0.261 X-Spam-Level: X-Archive-Number: 200511/480 X-Sequence-Number: 15737 This is a multi-part message in MIME format. --Boundary_(ID_QaxGn75YzNMJHffeg0xdpg) Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 8BIT Luke Lonergan wrote: > Mark, > > This is an excellent idea – unfortunately I’m in Maui right now > (Mahalo!) and I’m not getting to testing with this. My first try was > with 8.0.3 and it’s an 8.1 function I presume. > > Not to be lazy – but any hint as to how to do the same thing for 8.0? > Yeah, it's 8.1 - I didn't think to check against 8.0. The attached variant works with 8.0.4 (textToQualifiedNameList needs 2 args) cheers Mark P.s. Maui eh, sounds real nice. --Boundary_(ID_QaxGn75YzNMJHffeg0xdpg) Content-type: text/plain; name=fastcount-8.0.c Content-transfer-encoding: 7BIT Content-disposition: inline; filename=fastcount-8.0.c /* * fastcount.c * * Do a count that uses considerably less CPU time than an aggregate. * * (Variant for 8.0.x - textToQualifiedNameList needs 2 args) */ #include "postgres.h" #include "funcapi.h" #include "access/heapam.h" #include "catalog/namespace.h" #include "utils/builtins.h" extern Datum fastcount(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(fastcount); Datum fastcount(PG_FUNCTION_ARGS) { text *relname = PG_GETARG_TEXT_P(0); RangeVar *relrv; Relation rel; HeapScanDesc scan; HeapTuple tuple; int64 result = 0; /* Use the name to get a suitable range variable and open the relation. */ relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname, "")); rel = heap_openrv(relrv, AccessShareLock); /* Start a heap scan on the relation. */ scan = heap_beginscan(rel, SnapshotNow, 0, NULL); while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL) { result++; } /* End the scan and close up the relation. */ heap_endscan(scan); heap_close(rel, AccessShareLock); PG_RETURN_INT64(result); } --Boundary_(ID_QaxGn75YzNMJHffeg0xdpg)--