Enable variable shadowing warnings; fix all

Rather than wait for another place like the previous commit to bite us,
I think we should turn on this warning.
pull/2669/head
Jason Petersen 2019-04-16 17:09:56 -06:00
parent 1125fc9da0
commit 71d5d1c865
16 changed files with 104 additions and 77 deletions

35
configure vendored
View File

@ -4008,6 +4008,41 @@ if test x"$citusac_cv_prog_cc_cflags__Wmissing_prototypes" = x"yes"; then
CITUS_CFLAGS="$CITUS_CFLAGS -Wmissing-prototypes"
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Wshadow" >&5
$as_echo_n "checking whether $CC supports -Wshadow... " >&6; }
if ${citusac_cv_prog_cc_cflags__Wshadow+:} false; then :
$as_echo_n "(cached) " >&6
else
citusac_save_CFLAGS=$CFLAGS
CFLAGS="$citusac_save_CFLAGS -Wshadow"
ac_save_c_werror_flag=$ac_c_werror_flag
ac_c_werror_flag=yes
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
citusac_cv_prog_cc_cflags__Wshadow=yes
else
citusac_cv_prog_cc_cflags__Wshadow=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
ac_c_werror_flag=$ac_save_c_werror_flag
CFLAGS="$citusac_save_CFLAGS"
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $citusac_cv_prog_cc_cflags__Wshadow" >&5
$as_echo "$citusac_cv_prog_cc_cflags__Wshadow" >&6; }
if test x"$citusac_cv_prog_cc_cflags__Wshadow" = x"yes"; then
CITUS_CFLAGS="$CITUS_CFLAGS -Wshadow"
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=vla" >&5
$as_echo_n "checking whether $CC supports -Werror=vla... " >&6; }
if ${citusac_cv_prog_cc_cflags__Werror_vla+:} false; then :

View File

@ -163,6 +163,7 @@ CITUSAC_PROG_CC_CFLAGS_OPT([-Wendif-labels])
CITUSAC_PROG_CC_CFLAGS_OPT([-Wmissing-format-attribute])
CITUSAC_PROG_CC_CFLAGS_OPT([-Wmissing-declarations])
CITUSAC_PROG_CC_CFLAGS_OPT([-Wmissing-prototypes])
CITUSAC_PROG_CC_CFLAGS_OPT([-Wshadow])
CITUSAC_PROG_CC_CFLAGS_OPT([-Werror=vla]) # visual studio does not support these
#

View File

@ -696,7 +696,6 @@ EnsureRelationCanBeDistributed(Oid relationId, Var *distributionColumn,
/* partitions cannot be distributed if their parent is not distributed */
if (PartitionTable(relationId) && !IsDistributedTable(parentRelationId))
{
char *relationName = get_rel_name(relationId);
char *parentRelationName = get_rel_name(parentRelationId);
ereport(ERROR, (errmsg("cannot distribute relation \"%s\" which is partition of "
@ -734,8 +733,6 @@ EnsureRelationCanBeDistributed(Oid relationId, Var *distributionColumn,
/* we don't support distributing tables with multi-level partitioning */
if (PartitionTable(relationId))
{
char *relationName = get_rel_name(relationId);
Oid parentRelationId = PartitionParentOid(relationId);
char *parentRelationName = get_rel_name(parentRelationId);
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

View File

@ -667,13 +667,13 @@ FindPlacementListConnection(int flags, List *placementAccessList, const char *us
static ConnectionPlacementHashEntry *
FindOrCreatePlacementEntry(ShardPlacement *placement)
{
ConnectionPlacementHashKey key;
ConnectionPlacementHashKey connKey;
ConnectionPlacementHashEntry *placementEntry = NULL;
bool found = false;
key.placementId = placement->placementId;
connKey.placementId = placement->placementId;
placementEntry = hash_search(ConnectionPlacementHash, &key, HASH_ENTER, &found);
placementEntry = hash_search(ConnectionPlacementHash, &connKey, HASH_ENTER, &found);
if (!found)
{
/* no connection has been chosen for this placement */
@ -685,15 +685,15 @@ FindOrCreatePlacementEntry(ShardPlacement *placement)
if (placement->partitionMethod == DISTRIBUTE_BY_HASH ||
placement->partitionMethod == DISTRIBUTE_BY_NONE)
{
ColocatedPlacementsHashKey key;
ColocatedPlacementsHashKey coloKey;
ColocatedPlacementsHashEntry *colocatedEntry = NULL;
key.nodeId = placement->nodeId;
key.colocationGroupId = placement->colocationGroupId;
key.representativeValue = placement->representativeValue;
coloKey.nodeId = placement->nodeId;
coloKey.colocationGroupId = placement->colocationGroupId;
coloKey.representativeValue = placement->representativeValue;
/* look for a connection assigned to co-located placements */
colocatedEntry = hash_search(ColocatedPlacementsHash, &key, HASH_ENTER,
colocatedEntry = hash_search(ColocatedPlacementsHash, &coloKey, HASH_ENTER,
&found);
if (!found)
{
@ -857,10 +857,10 @@ AssociatePlacementWithShard(ConnectionPlacementHashEntry *placementEntry,
*/
dlist_foreach(placementIter, &shardEntry->placementConnections)
{
ConnectionPlacementHashEntry *placementEntry =
ConnectionPlacementHashEntry *currPlacementEntry =
dlist_container(ConnectionPlacementHashEntry, shardNode, placementIter.cur);
if (placementEntry->key.placementId == placement->placementId)
if (currPlacementEntry->key.placementId == placement->placementId)
{
return;
}

View File

@ -133,8 +133,8 @@ MultiRealTimeExecute(Job *job)
uint32 completedTaskCount = 0;
/* loop around all tasks and manage them */
ListCell *taskCell = NULL;
ListCell *taskExecutionCell = NULL;
taskCell = NULL;
taskExecutionCell = NULL;
MultiClientResetWaitInfo(waitInfo);

View File

@ -235,7 +235,6 @@ MultiTaskTrackerExecute(Job *job)
double acceptableHealthyTrackerCount = 0.0;
/* first, loop around all tasks and manage them */
ListCell *taskAndExecutionCell = NULL;
foreach(taskAndExecutionCell, taskAndExecutionList)
{
Task *task = (Task *) lfirst(taskAndExecutionCell);
@ -259,7 +258,6 @@ MultiTaskTrackerExecute(Job *job)
if (taskExecutionStatus == EXEC_TASK_TRACKER_FAILED)
{
List *taskList = NIL;
TaskTracker *transmitTracker = NULL;
/* mark task tracker as failed, in case it isn't marked already */
execTaskTracker->trackerFailureCount = MAX_TRACKER_FAILURE_COUNT;
@ -343,7 +341,6 @@ MultiTaskTrackerExecute(Job *job)
if (transmitExecutionStatus == EXEC_TRANSMIT_TRACKER_FAILED)
{
List *taskList = NIL;
TaskTracker *taskTracker = NULL;
taskTracker = ResolveTaskTracker(taskTrackerHash,
task, taskExecution);
@ -2358,7 +2355,7 @@ AssignQueuedTasks(TaskTracker *taskTracker)
foreach(taskCell, tasksToAssignList)
{
TrackerTaskState *taskState = (TrackerTaskState *) lfirst(taskCell);
taskState = (TrackerTaskState *) lfirst(taskCell);
BatchQueryStatus queryStatus = CLIENT_INVALID_BATCH_QUERY;
if (!batchSuccess)
@ -2663,14 +2660,14 @@ JobIdList(Job *job)
uint64 *jobIdPointer = (uint64 *) palloc0(sizeof(uint64));
List *jobChildrenList = NIL;
Job *job = (Job *) linitial(jobQueue);
Job *currJob = (Job *) linitial(jobQueue);
jobQueue = list_delete_first(jobQueue);
(*jobIdPointer) = job->jobId;
(*jobIdPointer) = currJob->jobId;
jobIdList = lappend(jobIdList, jobIdPointer);
/* prevent dependedJobList being modified on list_concat() call */
jobChildrenList = list_copy(job->dependedJobList);
jobChildrenList = list_copy(currJob->dependedJobList);
if (jobChildrenList != NIL)
{
jobQueue = list_concat(jobQueue, jobChildrenList);
@ -2907,7 +2904,7 @@ TrackerHashCleanupJob(HTAB *taskTrackerHash, Task *jobCleanupTask)
foreach(activeTaskTrackerCell, activeTackTrackerList)
{
TaskTracker *taskTracker = (TaskTracker *) lfirst(activeTaskTrackerCell);
taskTracker = (TaskTracker *) lfirst(activeTaskTrackerCell);
int32 connectionId = taskTracker->connectionId;
const char *nodeName = taskTracker->workerName;
uint32 nodePort = taskTracker->workerPort;

View File

@ -471,7 +471,6 @@ master_get_active_worker_nodes(PG_FUNCTION_ARGS)
{
MemoryContext oldContext = NULL;
List *workerNodeList = NIL;
uint32 workerNodeCount = 0;
TupleDesc tupleDescriptor = NULL;
bool hasOid = false;

View File

@ -378,8 +378,6 @@ DistributedInsertSelectSupported(Query *queryTree, RangeTblEntry *insertRte,
}
else
{
DeferredErrorMessage *error = NULL;
/* ensure that INSERT's partition column comes from SELECT's partition column */
error = InsertPartitionColumnMatchesSelect(queryTree, insertRte, subqueryRte,
&selectPartitionColumnTableId);

View File

@ -939,9 +939,8 @@ SinglePartitionJoin(JoinOrderNode *currentJoinNode, TableEntry *candidateTable,
/* evaluate re-partitioning the current table only if the rule didn't apply above */
if (nextJoinNode == NULL && candidatePartitionMethod != DISTRIBUTE_BY_NONE)
{
OpExpr *joinClause = SinglePartitionJoinClause(candidatePartitionColumn,
applicableJoinClauses);
joinClause = SinglePartitionJoinClause(candidatePartitionColumn,
applicableJoinClauses);
if (joinClause != NULL)
{
if (candidatePartitionMethod == DISTRIBUTE_BY_HASH)

View File

@ -4239,23 +4239,23 @@ HasOrderByHllType(List *sortClauseList, List *targetList)
* of distinct clause.
*/
bool
IsGroupBySubsetOfDistinct(List *groupClause, List *distinctClause)
IsGroupBySubsetOfDistinct(List *groupClauses, List *distinctClauses)
{
ListCell *distinctCell = NULL;
ListCell *groupCell = NULL;
/* There must be a group clause */
if (list_length(groupClause) == 0)
if (list_length(groupClauses) == 0)
{
return false;
}
foreach(groupCell, groupClause)
foreach(groupCell, groupClauses)
{
SortGroupClause *groupClause = (SortGroupClause *) lfirst(groupCell);
bool isFound = false;
foreach(distinctCell, distinctClause)
foreach(distinctCell, distinctClauses)
{
SortGroupClause *distinctClause = (SortGroupClause *) lfirst(distinctCell);

View File

@ -814,8 +814,8 @@ BaseRangeTableList(MultiNode *multiNode)
while (pendingNodeList != NIL)
{
MultiNode *multiNode = (MultiNode *) linitial(pendingNodeList);
CitusNodeTag nodeType = CitusNodeTag(multiNode);
MultiNode *currMultiNode = (MultiNode *) linitial(pendingNodeList);
CitusNodeTag nodeType = CitusNodeTag(currMultiNode);
pendingNodeList = list_delete_first(pendingNodeList);
if (nodeType == T_MultiTable)
@ -824,7 +824,7 @@ BaseRangeTableList(MultiNode *multiNode)
* We represent subqueries as MultiTables, and so for base table
* entries we skip the subquery ones.
*/
MultiTable *multiTable = (MultiTable *) multiNode;
MultiTable *multiTable = (MultiTable *) currMultiNode;
if (multiTable->relationId != SUBQUERY_RELATION_ID &&
multiTable->relationId != SUBQUERY_PUSHDOWN_RELATION_ID)
{
@ -843,7 +843,7 @@ BaseRangeTableList(MultiNode *multiNode)
/* do not visit nodes that belong to remote queries */
if (nodeType != T_MultiCollect)
{
List *childNodeList = ChildNodeList(multiNode);
List *childNodeList = ChildNodeList(currMultiNode);
pendingNodeList = list_concat(pendingNodeList, childNodeList);
}
}
@ -963,21 +963,21 @@ QueryGroupClauseList(MultiNode *multiNode)
while (pendingNodeList != NIL)
{
MultiNode *multiNode = (MultiNode *) linitial(pendingNodeList);
CitusNodeTag nodeType = CitusNodeTag(multiNode);
MultiNode *currMultiNode = (MultiNode *) linitial(pendingNodeList);
CitusNodeTag nodeType = CitusNodeTag(currMultiNode);
pendingNodeList = list_delete_first(pendingNodeList);
/* extract the group clause list from the extended operator */
if (nodeType == T_MultiExtendedOp)
{
MultiExtendedOp *extendedOpNode = (MultiExtendedOp *) multiNode;
MultiExtendedOp *extendedOpNode = (MultiExtendedOp *) currMultiNode;
groupClauseList = extendedOpNode->groupClauseList;
}
/* add children only if this node isn't a multi collect and multi table */
if (nodeType != T_MultiCollect && nodeType != T_MultiTable)
{
List *childNodeList = ChildNodeList(multiNode);
List *childNodeList = ChildNodeList(currMultiNode);
pendingNodeList = list_concat(pendingNodeList, childNodeList);
}
}
@ -1000,14 +1000,14 @@ QuerySelectClauseList(MultiNode *multiNode)
while (pendingNodeList != NIL)
{
MultiNode *multiNode = (MultiNode *) linitial(pendingNodeList);
CitusNodeTag nodeType = CitusNodeTag(multiNode);
MultiNode *currMultiNode = (MultiNode *) linitial(pendingNodeList);
CitusNodeTag nodeType = CitusNodeTag(currMultiNode);
pendingNodeList = list_delete_first(pendingNodeList);
/* extract select clauses from the multi select node */
if (nodeType == T_MultiSelect)
{
MultiSelect *selectNode = (MultiSelect *) multiNode;
MultiSelect *selectNode = (MultiSelect *) currMultiNode;
List *clauseList = copyObject(selectNode->selectClauseList);
selectClauseList = list_concat(selectClauseList, clauseList);
}
@ -1015,7 +1015,7 @@ QuerySelectClauseList(MultiNode *multiNode)
/* add children only if this node isn't a multi collect */
if (nodeType != T_MultiCollect)
{
List *childNodeList = ChildNodeList(multiNode);
List *childNodeList = ChildNodeList(currMultiNode);
pendingNodeList = list_concat(pendingNodeList, childNodeList);
}
}
@ -1038,14 +1038,14 @@ QueryJoinClauseList(MultiNode *multiNode)
while (pendingNodeList != NIL)
{
MultiNode *multiNode = (MultiNode *) linitial(pendingNodeList);
CitusNodeTag nodeType = CitusNodeTag(multiNode);
MultiNode *currMultiNode = (MultiNode *) linitial(pendingNodeList);
CitusNodeTag nodeType = CitusNodeTag(currMultiNode);
pendingNodeList = list_delete_first(pendingNodeList);
/* extract join clauses from the multi join node */
if (nodeType == T_MultiJoin)
{
MultiJoin *joinNode = (MultiJoin *) multiNode;
MultiJoin *joinNode = (MultiJoin *) currMultiNode;
List *clauseList = copyObject(joinNode->joinClauseList);
joinClauseList = list_concat(joinClauseList, clauseList);
}
@ -1053,7 +1053,7 @@ QueryJoinClauseList(MultiNode *multiNode)
/* add this node's children only if the node isn't a multi collect */
if (nodeType != T_MultiCollect)
{
List *childNodeList = ChildNodeList(multiNode);
List *childNodeList = ChildNodeList(currMultiNode);
pendingNodeList = list_concat(pendingNodeList, childNodeList);
}
}
@ -1726,8 +1726,8 @@ static List *
ChildNodeList(MultiNode *multiNode)
{
List *childNodeList = NIL;
bool unaryNode = UnaryOperator(multiNode);
bool binaryNode = BinaryOperator(multiNode);
bool isUnaryNode = UnaryOperator(multiNode);
bool isBinaryNode = BinaryOperator(multiNode);
/* relation table nodes don't have any children */
if (CitusIsA(multiNode, MultiTable))
@ -1739,12 +1739,12 @@ ChildNodeList(MultiNode *multiNode)
}
}
if (unaryNode)
if (isUnaryNode)
{
MultiUnaryNode *unaryNode = (MultiUnaryNode *) multiNode;
childNodeList = list_make1(unaryNode->childNode);
}
else if (binaryNode)
else if (isBinaryNode)
{
MultiBinaryNode *binaryNode = (MultiBinaryNode *) multiNode;
childNodeList = list_make2(binaryNode->leftChildNode,

View File

@ -2416,10 +2416,10 @@ BuildRoutesForInsert(Query *query, DeferredErrorMessage **planningError)
DISTRIBUTE_BY_RANGE)
{
Datum partitionValue = partitionValueConst->constvalue;
DistTableCacheEntry *cacheEntry = DistributedTableCacheEntry(
distributedTableId);
ShardInterval *shardInterval = FindShardInterval(partitionValue, cacheEntry);
ShardInterval *shardInterval = NULL;
cacheEntry = DistributedTableCacheEntry(distributedTableId);
shardInterval = FindShardInterval(partitionValue, cacheEntry);
if (shardInterval != NULL)
{
prunedShardList = list_make1(shardInterval);

View File

@ -40,7 +40,7 @@
static bool allowNonIdleRemoteTransactionOnXactHandling = false;
static MultiConnection *connection = NULL;
static MultiConnection *singleConnection = NULL;
/*
@ -51,7 +51,7 @@ int IsolationTestSessionRemoteProcessID = -1;
int IsolationTestSessionProcessID = -1;
static int64 GetRemoteProcessId(MultiConnection *connection);
static int64 GetRemoteProcessId(void);
/* declarations for dynamic loading */
PG_FUNCTION_INFO_V1(start_session_level_connection_to_node);
@ -88,8 +88,9 @@ start_session_level_connection_to_node(PG_FUNCTION_ARGS)
CheckCitusVersion(ERROR);
if (connection != NULL && (strcmp(connection->hostname, nodeNameString) != 0 ||
connection->port != nodePort))
if (singleConnection != NULL && (strcmp(singleConnection->hostname,
nodeNameString) != 0 ||
singleConnection->port != nodePort))
{
elog(ERROR,
"can not connect different worker nodes from the same session using start_session_level_connection_to_node");
@ -99,13 +100,13 @@ start_session_level_connection_to_node(PG_FUNCTION_ARGS)
* In order to keep connection open even with an open transaction,
* allowSessionLifeSpanWithOpenTransaction is set to true.
*/
if (connection == NULL)
if (singleConnection == NULL)
{
connection = GetNodeConnection(SESSION_LIFESPAN, nodeNameString, nodePort);
singleConnection = GetNodeConnection(SESSION_LIFESPAN, nodeNameString, nodePort);
allowNonIdleRemoteTransactionOnXactHandling = true;
}
if (PQstatus(connection->pgConn) != CONNECTION_OK)
if (PQstatus(singleConnection->pgConn) != CONNECTION_OK)
{
elog(ERROR, "failed to connect to %s:%d", nodeNameString, (int) nodePort);
}
@ -136,7 +137,7 @@ run_commands_on_session_level_connection_to_node(PG_FUNCTION_ARGS)
PostPortNumber);
Oid pgReloadConfOid = InvalidOid;
if (!connection)
if (!singleConnection)
{
elog(ERROR,
"start_session_level_connection_to_node must be called first to open a session level connection");
@ -144,9 +145,9 @@ run_commands_on_session_level_connection_to_node(PG_FUNCTION_ARGS)
appendStringInfo(processStringInfo, ALTER_CURRENT_PROCESS_ID, MyProcPid);
appendStringInfo(workerProcessStringInfo, ALTER_CURRENT_WORKER_PROCESS_ID,
GetRemoteProcessId(connection));
GetRemoteProcessId());
ExecuteCriticalRemoteCommand(connection, queryString);
ExecuteCriticalRemoteCommand(singleConnection, queryString);
/*
* Since we cannot run `ALTER SYSTEM` command within a transaction, we are
@ -176,10 +177,10 @@ stop_session_level_connection_to_node(PG_FUNCTION_ARGS)
{
allowNonIdleRemoteTransactionOnXactHandling = false;
if (connection != NULL)
if (singleConnection != NULL)
{
CloseConnection(connection);
connection = NULL;
CloseConnection(singleConnection);
singleConnection = NULL;
}
PG_RETURN_VOID();
@ -191,7 +192,7 @@ stop_session_level_connection_to_node(PG_FUNCTION_ARGS)
* by the connection.
*/
static int64
GetRemoteProcessId(MultiConnection *connection)
GetRemoteProcessId()
{
StringInfo queryStringInfo = makeStringInfo();
PGresult *result = NULL;
@ -200,7 +201,7 @@ GetRemoteProcessId(MultiConnection *connection)
appendStringInfo(queryStringInfo, GET_PROCESS_ID);
ExecuteOptionalRemoteCommand(connection, queryStringInfo->data, &result);
ExecuteOptionalRemoteCommand(singleConnection, queryStringInfo->data, &result);
rowCount = PQntuples(result);
@ -212,7 +213,7 @@ GetRemoteProcessId(MultiConnection *connection)
resultValue = ParseIntField(result, 0, 0);
PQclear(result);
ClearResults(connection, false);
ClearResults(singleConnection, false);
return resultValue;
}

View File

@ -16,9 +16,9 @@
* ApplyLogRedaction is only supported in Citus Enterprise
*/
char *
ApplyLogRedaction(const char *text)
ApplyLogRedaction(const char *logText)
{
return (char *) text;
return (char *) logText;
}

View File

@ -445,8 +445,8 @@ SingleReplicatedTable(Oid relationId)
foreach(shardIntervalCell, shardIntervalList)
{
uint64 *shardIdPointer = (uint64 *) lfirst(shardIntervalCell);
uint64 shardId = (*shardIdPointer);
List *shardPlacementList = ShardPlacementList(shardId);
shardId = (*shardIdPointer);
shardPlacementList = ShardPlacementList(shardId);
if (list_length(shardPlacementList) != 1)
{

View File

@ -146,6 +146,6 @@ extern bool IsPartitionColumn(Expr *columnExpression, Query *query);
extern void FindReferencedTableColumn(Expr *columnExpression, List *parentQueryList,
Query *query, Oid *relationId, Var **column);
extern bool IsGroupBySubsetOfDistinct(List *groupClause, List *distinctClause);
extern bool IsGroupBySubsetOfDistinct(List *groupClauses, List *distinctClauses);
#endif /* MULTI_LOGICAL_OPTIMIZER_H */