This is an automated email from the ASF dual-hosted git repository.
ztao1987 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hawq.git
The following commit(s) were added to refs/heads/master by this push:
new e9d43144f HAWQ-1855. Fix access to the uninitialized variable database
e9d43144f is described below
commit e9d43144f7e947e071bba48871af9da354d177d0
Author: ztao1987 <[email protected]>
AuthorDate: Sat Feb 4 16:00:42 2023 +0800
HAWQ-1855. Fix access to the uninitialized variable database
---
src/backend/executor/execMain.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 12de33a5d..8df651821 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -2168,7 +2168,26 @@ InitPlan(QueryDesc *queryDesc, int eflags)
estate->es_evTupleNull = NULL;
estate->es_evTuple = NULL;
estate->es_useEvalPlan = false;
-
+
+ /*
+ * In QD, we need to initialize the variable database before
+ * ExecInitNode(), that makes us can access the database
+ * correctly in places such as magma_beginscan(),
+ * magma_insertinit().
+ *
+ * In contrast, if we are in QE, we don't need to do this since
+ * RebuildDatabase() ensures that the database is initialized.
+ *
+ * An example of the uninitialized database:
+ * prepare select_by_id(int) as select * from t where id = 1;
+ * execute select_by_id(1); <- uninitialized when we are in
+ * magma_beginscan()
+ */
+ if (Gp_role == GP_ROLE_DISPATCH)
+ {
+ database = get_database_name(MyDatabaseId);
+ }
+
/*
* Initialize the private state information for all the nodes in the
query
* tree. This opens files, allocates storage and leaves us ready to
start