Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 57F3CB5DBF2 for ; Wed, 22 Jun 2011 01:56:26 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 81865-07 for ; Wed, 22 Jun 2011 04:56:20 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from midnight-anchovy.ambulatoryclam.net (unknown [18.141.0.210]) by mail.postgresql.org (Postfix) with ESMTP id 19EBFB5DBF0 for ; Wed, 22 Jun 2011 01:56:19 -0300 (ADT) Received: by midnight-anchovy.ambulatoryclam.net (Postfix, from userid 1001) id 8CB504AC24; Wed, 22 Jun 2011 00:58:50 -0400 (EDT) Date: Wed, 22 Jun 2011 00:58:50 -0400 From: Dan Ports To: pgsql-hackers@postgresql.org, Kevin Grittner Subject: Repeated PredicateLockRelation calls during seqscan Message-ID: <20110622045850.GN83336@csail.mit.edu> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="OBd5C1Lgu00Gd/Tn" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.107 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RDNS_NONE=0.793 X-Spam-Level: X-Archive-Number: 201106/1860 X-Sequence-Number: 190573 --OBd5C1Lgu00Gd/Tn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I was looking at ExecSeqScan today and noticed that it invokes PredicateLockRelation each time it's called, i.e. for each tuple returned. Any reason we shouldn't skip that call if rs_relpredicatelocked is already set, as in the attached patch? That would save us a bit of overhead, since checking that flag is cheaper than doing a hash lookup in the local predicate lock table before bailing out. Dan -- Dan R. K. Ports MIT CSAIL http://drkp.net/ --OBd5C1Lgu00Gd/Tn Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="predlock-seqscan.patch" diff --git a/src/backend/executor/nodeSeqscan.c b/src/backend/executor/nodeSeqscan.c index f356874..32a8f56 100644 --- a/src/backend/executor/nodeSeqscan.c +++ b/src/backend/executor/nodeSeqscan.c @@ -113,9 +113,13 @@ SeqRecheck(SeqScanState *node, TupleTableSlot *slot) TupleTableSlot * ExecSeqScan(SeqScanState *node) { - PredicateLockRelation(node->ss_currentRelation, - node->ss_currentScanDesc->rs_snapshot); - node->ss_currentScanDesc->rs_relpredicatelocked = true; + if (!node->ss_currentScanDesc->rs_relpredicatelocked) + { + PredicateLockRelation(node->ss_currentRelation, + node->ss_currentScanDesc->rs_snapshot); + node->ss_currentScanDesc->rs_relpredicatelocked = true; + } + return ExecScan((ScanState *) node, (ExecScanAccessMtd) SeqNext, (ExecScanRecheckMtd) SeqRecheck); --OBd5C1Lgu00Gd/Tn--