1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-11 10:01:57 +03:00

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
This commit is contained in:
Tom Lane
2017-04-10 13:51:29 -04:00
parent 56dd8e85c4
commit 8f0530f580
65 changed files with 176 additions and 168 deletions

View File

@ -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))