mirror of https://github.com/citusdata/citus.git
Handle some NULL issues that static analysis found (#4001)
Static analysis found some issues where we used the result from
ExtractResultRelationRTE, without checking that it wasn't NULL. It seems
like in all these cases it can never actually be NULL, since we have checked
before that it isn't a SELECT query. So, this PR is mostly to make static
analysis happy (and protect a bit against future changes of the code).
(cherry picked from commit 759e628dd5
)
pull/4206/head
parent
49d23229c4
commit
55eed7f2ec
|
@ -74,7 +74,7 @@ RebuildQueryStrings(Job *workerJob)
|
|||
|
||||
query = copyObject(originalQuery);
|
||||
|
||||
RangeTblEntry *copiedInsertRte = ExtractResultRelationRTE(query);
|
||||
RangeTblEntry *copiedInsertRte = ExtractResultRelationRTEOrError(query);
|
||||
RangeTblEntry *copiedSubqueryRte = ExtractSelectRangeTableEntry(query);
|
||||
Query *copiedSubquery = copiedSubqueryRte->subquery;
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ CreateDistributedInsertSelectPlan(Query *originalQuery,
|
|||
uint32 taskIdIndex = 1; /* 0 is reserved for invalid taskId */
|
||||
uint64 jobId = INVALID_JOB_ID;
|
||||
DistributedPlan *distributedPlan = CitusMakeNode(DistributedPlan);
|
||||
RangeTblEntry *insertRte = ExtractResultRelationRTE(originalQuery);
|
||||
RangeTblEntry *insertRte = ExtractResultRelationRTEOrError(originalQuery);
|
||||
RangeTblEntry *subqueryRte = ExtractSelectRangeTableEntry(originalQuery);
|
||||
Oid targetRelationId = insertRte->relid;
|
||||
CitusTableCacheEntry *targetCacheEntry = GetCitusTableCacheEntry(targetRelationId);
|
||||
|
@ -648,7 +648,7 @@ RouterModifyTaskForShardInterval(Query *originalQuery,
|
|||
DeferredErrorMessage **routerPlannerError)
|
||||
{
|
||||
Query *copiedQuery = copyObject(originalQuery);
|
||||
RangeTblEntry *copiedInsertRte = ExtractResultRelationRTE(copiedQuery);
|
||||
RangeTblEntry *copiedInsertRte = ExtractResultRelationRTEOrError(copiedQuery);
|
||||
RangeTblEntry *copiedSubqueryRte = ExtractSelectRangeTableEntry(copiedQuery);
|
||||
Query *copiedSubquery = (Query *) copiedSubqueryRte->subquery;
|
||||
|
||||
|
@ -1343,7 +1343,7 @@ CreateNonPushableInsertSelectPlan(uint64 planId, Query *parse, ParamListInfo bou
|
|||
Query *insertSelectQuery = copyObject(parse);
|
||||
|
||||
RangeTblEntry *selectRte = ExtractSelectRangeTableEntry(insertSelectQuery);
|
||||
RangeTblEntry *insertRte = ExtractResultRelationRTE(insertSelectQuery);
|
||||
RangeTblEntry *insertRte = ExtractResultRelationRTEOrError(insertSelectQuery);
|
||||
Oid targetRelationId = insertRte->relid;
|
||||
|
||||
DistributedPlan *distributedPlan = CitusMakeNode(DistributedPlan);
|
||||
|
|
|
@ -508,7 +508,9 @@ ResultRelationOidForQuery(Query *query)
|
|||
|
||||
|
||||
/*
|
||||
* ExtractResultRelationRTE returns the table's resultRelation range table entry.
|
||||
* ExtractResultRelationRTE returns the table's resultRelation range table
|
||||
* entry. This returns NULL when there's no resultRelation, such as in a SELECT
|
||||
* query.
|
||||
*/
|
||||
RangeTblEntry *
|
||||
ExtractResultRelationRTE(Query *query)
|
||||
|
@ -522,6 +524,28 @@ ExtractResultRelationRTE(Query *query)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* ExtractResultRelationRTEOrError returns the table's resultRelation range table
|
||||
* entry and errors out if there's no result relation at all, e.g. like in a
|
||||
* SELECT query.
|
||||
*
|
||||
* This is a separate function (instead of using missingOk), so static analysis
|
||||
* reasons about NULL returns correctly.
|
||||
*/
|
||||
RangeTblEntry *
|
||||
ExtractResultRelationRTEOrError(Query *query)
|
||||
{
|
||||
RangeTblEntry *relation = ExtractResultRelationRTE(query);
|
||||
if (relation == NULL)
|
||||
{
|
||||
ereport(ERROR, (errmsg("no result relation could be found for the query"),
|
||||
errhint("is this a SELECT query?")));
|
||||
}
|
||||
|
||||
return relation;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* IsTidColumn gets a node and returns true if the node is a Var type of TID.
|
||||
*/
|
||||
|
|
|
@ -71,6 +71,7 @@ extern Oid ExtractFirstCitusTableId(Query *query);
|
|||
extern RangeTblEntry * ExtractSelectRangeTableEntry(Query *query);
|
||||
extern Oid ModifyQueryResultRelationId(Query *query);
|
||||
extern RangeTblEntry * ExtractResultRelationRTE(Query *query);
|
||||
extern RangeTblEntry * ExtractResultRelationRTEOrError(Query *query);
|
||||
extern RangeTblEntry * ExtractDistributedInsertValuesRTE(Query *query);
|
||||
extern bool IsMultiRowInsert(Query *query);
|
||||
extern void AddShardIntervalRestrictionToSelect(Query *subqery,
|
||||
|
|
Loading…
Reference in New Issue