summaryrefslogtreecommitdiff
path: root/src/backend/utils/cache/plancache.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-04-10 13:51:29 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2017-04-10 13:51:53 -0400
commit8f0530f58061b185dc385df42e62d78a18d4ae3e (patch)
tree63d038ae4012dcdcff3b556dde4c654959f8448e /src/backend/utils/cache/plancache.c
parent56dd8e85c40fef3e3c2c10afa186ee30416ec507 (diff)
downloadpostgresql-8f0530f58061b185dc385df42e62d78a18d4ae3e.tar.gz
Improve castNode notation by introducing list-extraction-specific variants.
This extends the castNode() notation introduced by commit 5bcab1114 to provide, in one step, extraction of a list cell's pointer and coercion to a concrete node type. For example, "lfirst_node(Foo, lc)" is the same as "castNode(Foo, lfirst(lc))". Almost half of the uses of castNode that have appeared so far include a list extraction call, so this is pretty widely useful, and it saves a few more keystrokes compared to the old way. As with the previous patch, back-patch the addition of these macros to pg_list.h, so that the notation will be available when back-patching. Patch by me, after an idea of Andrew Gierth's. Discussion: https://postgr.es/m/14197.1491841216@sss.pgh.pa.us
Diffstat (limited to 'src/backend/utils/cache/plancache.c')
-rw-r--r--src/backend/utils/cache/plancache.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index 50da116cf4..abff7474f5 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -979,7 +979,7 @@ BuildCachedPlan(CachedPlanSource *plansource, List *qlist,
is_transient = false;
foreach(lc, plist)
{
- PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc));
+ PlannedStmt *plannedstmt = lfirst_node(PlannedStmt, lc);
if (plannedstmt->commandType == CMD_UTILITY)
continue; /* Ignore utility statements */
@@ -1074,7 +1074,7 @@ cached_plan_cost(CachedPlan *plan, bool include_planner)
foreach(lc, plan->stmt_list)
{
- PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc));
+ PlannedStmt *plannedstmt = lfirst_node(PlannedStmt, lc);
if (plannedstmt->commandType == CMD_UTILITY)
continue; /* Ignore utility statements */
@@ -1462,7 +1462,7 @@ QueryListGetPrimaryStmt(List *stmts)
foreach(lc, stmts)
{
- Query *stmt = castNode(Query, lfirst(lc));
+ Query *stmt = lfirst_node(Query, lc);
if (stmt->canSetTag)
return stmt;
@@ -1481,7 +1481,7 @@ AcquireExecutorLocks(List *stmt_list, bool acquire)
foreach(lc1, stmt_list)
{
- PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc1));
+ PlannedStmt *plannedstmt = lfirst_node(PlannedStmt, lc1);
int rt_index;
ListCell *lc2;
@@ -1551,7 +1551,7 @@ AcquirePlannerLocks(List *stmt_list, bool acquire)
foreach(lc, stmt_list)
{
- Query *query = castNode(Query, lfirst(lc));
+ Query *query = lfirst_node(Query, lc);
if (query->commandType == CMD_UTILITY)
{
@@ -1618,7 +1618,7 @@ ScanQueryForLocks(Query *parsetree, bool acquire)
/* Recurse into subquery-in-WITH */
foreach(lc, parsetree->cteList)
{
- CommonTableExpr *cte = castNode(CommonTableExpr, lfirst(lc));
+ CommonTableExpr *cte = lfirst_node(CommonTableExpr, lc);
ScanQueryForLocks(castNode(Query, cte->ctequery), acquire);
}
@@ -1676,7 +1676,7 @@ PlanCacheComputeResultDesc(List *stmt_list)
{
case PORTAL_ONE_SELECT:
case PORTAL_ONE_MOD_WITH:
- query = castNode(Query, linitial(stmt_list));
+ query = linitial_node(Query, stmt_list);
return ExecCleanTypeFromTL(query->targetList, false);
case PORTAL_ONE_RETURNING:
@@ -1685,7 +1685,7 @@ PlanCacheComputeResultDesc(List *stmt_list)
return ExecCleanTypeFromTL(query->returningList, false);
case PORTAL_UTIL_SELECT:
- query = castNode(Query, linitial(stmt_list));
+ query = linitial_node(Query, stmt_list);
Assert(query->utilityStmt);
return UtilityTupleDescriptor(query->utilityStmt);
@@ -1742,7 +1742,7 @@ PlanCacheRelCallback(Datum arg, Oid relid)
foreach(lc, plansource->gplan->stmt_list)
{
- PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc));
+ PlannedStmt *plannedstmt = lfirst_node(PlannedStmt, lc);
if (plannedstmt->commandType == CMD_UTILITY)
continue; /* Ignore utility statements */
@@ -1815,7 +1815,7 @@ PlanCacheFuncCallback(Datum arg, int cacheid, uint32 hashvalue)
{
foreach(lc, plansource->gplan->stmt_list)
{
- PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc));
+ PlannedStmt *plannedstmt = lfirst_node(PlannedStmt, lc);
ListCell *lc3;
if (plannedstmt->commandType == CMD_UTILITY)
@@ -1888,7 +1888,7 @@ ResetPlanCache(void)
*/
foreach(lc, plansource->query_list)
{
- Query *query = castNode(Query, lfirst(lc));
+ Query *query = lfirst_node(Query, lc);
if (query->commandType != CMD_UTILITY ||
UtilityContainsQuery(query->utilityStmt))