You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by jg...@apache.org on 2023/01/11 18:22:16 UTC
[age] branch experimental/PG14 updated: compat/PG14/1.1.0 (#360)
This is an automated email from the ASF dual-hosted git repository.
jgemignani pushed a commit to branch experimental/PG14
in repository https://gitbox.apache.org/repos/asf/age.git
The following commit(s) were added to refs/heads/experimental/PG14 by this push:
new 0d3d613 compat/PG14/1.1.0 (#360)
0d3d613 is described below
commit 0d3d613336c859b27fe3b1f88516c085380ae8e9
Author: amolinaitrs <40...@users.noreply.github.com>
AuthorDate: Wed Jan 11 19:22:11 2023 +0100
compat/PG14/1.1.0 (#360)
* experimental/PG14/1.1.0
---
.github/workflows/installcheck.yml | 26 +--
.gitignore | 1 +
.travis.yml | 6 +-
Dockerfile | 10 +-
Makefile | 4 +-
README.md | 7 +-
RELEASE | 4 +-
regress/expected/expr.out | 12 +-
src/backend/catalog/ag_catalog.c | 16 +-
src/backend/commands/label_commands.c | 17 +-
src/backend/executor/cypher_create.c | 30 +--
src/backend/executor/cypher_delete.c | 8 +-
src/backend/executor/cypher_merge.c | 30 +--
src/backend/executor/cypher_set.c | 18 +-
src/backend/executor/cypher_utils.c | 2 +-
src/backend/parser/ag_scanner.l | 11 -
src/backend/parser/cypher_analyze.c | 32 +--
src/backend/parser/cypher_clause.c | 388 ++++++++++++++++++-------------
src/backend/parser/cypher_expr.c | 43 ++--
src/backend/parser/cypher_gram.y | 4 +-
src/backend/parser/cypher_item.c | 11 +-
src/backend/parser/cypher_parse_agg.c | 4 +-
src/backend/parser/cypher_parse_node.c | 19 --
src/backend/utils/adt/age_global_graph.c | 1 +
src/backend/utils/adt/age_vle.c | 1 +
src/backend/utils/adt/agtype_gin.c | 2 -
src/backend/utils/cache/ag_cache.c | 12 +-
src/include/parser/cypher_parse_node.h | 1 -
28 files changed, 387 insertions(+), 333 deletions(-)
diff --git a/.github/workflows/installcheck.yml b/.github/workflows/installcheck.yml
index 76503fe..b1a1292 100644
--- a/.github/workflows/installcheck.yml
+++ b/.github/workflows/installcheck.yml
@@ -1,4 +1,4 @@
-name: PG12 Regression
+name: PG14 Regression
on:
push:
@@ -12,29 +12,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- - name: Get latest commit id of PostgreSQL 12
+ - name: Get latest commit id of PostgreSQL 14
run: |
- echo "PG_COMMIT_HASH=$(git ls-remote git://git.postgresql.org/git/postgresql.git refs/heads/REL_12_STABLE | awk '{print $1}')" >> $GITHUB_ENV
+ echo "PG_COMMIT_HASH=$(git ls-remote git://git.postgresql.org/git/postgresql.git refs/heads/REL_14_STABLE | awk '{print $1}')" >> $GITHUB_ENV
- - name: Cache PostgreSQL 12
+ - name: Cache PostgreSQL 14
uses: actions/cache@v2
- id: pg12cache
+ id: pg14cache
with:
- path: ~/pg12
- key: ${{ runner.os }}-v1-pg12-${{ env.PG_COMMIT_HASH }}
+ path: ~/pg14
+ key: ${{ runner.os }}-v1-pg14-${{ env.PG_COMMIT_HASH }}
- - name: Install PostgreSQL 12
- if: steps.pg12cache.outputs.cache-hit != 'true'
+ - name: Install PostgreSQL 14
+ if: steps.pg14cache.outputs.cache-hit != 'true'
run: |
- git clone --depth 1 --branch REL_12_STABLE git://git.postgresql.org/git/postgresql.git ~/pg12source
- cd ~/pg12source
- ./configure --prefix=$HOME/pg12 CFLAGS="-std=gnu99 -ggdb -O0" --enable-cassert
+ git clone --depth 1 --branch REL_14_STABLE git://git.postgresql.org/git/postgresql.git ~/pg14source
+ cd ~/pg14source
+ ./configure --prefix=$HOME/pg14 CFLAGS="-std=gnu99 -ggdb -O0" --enable-cassert
make install -j$(nproc) > /dev/null
- uses: actions/checkout@v2
- name: Regression
run: |
- export PG_CONFIG=$HOME/pg12/bin/pg_config
+ export PG_CONFIG=$HOME/pg14/bin/pg_config
make -j$(nproc)
make install
make installcheck
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 46a9360..3909fa4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ build.sh
.idea
.deps
.DS_Store
+.vscode
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index b8c9a5a..61cba1c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,13 +4,13 @@ dist: bionic
arch: amd64
jobs:
include:
- - name: PostgreSQL 12
+ - name: PostgreSQL 14
compiler: gcc
addons:
apt:
packages:
- - postgresql-12
- - postgresql-server-dev-12
+ - postgresql-14
+ - postgresql-server-dev-14
script:
- sudo make install -j$(nproc)
- make installcheck
diff --git a/Dockerfile b/Dockerfile
index cd9622c..42daf55 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -17,17 +17,17 @@
#
-FROM postgres:12
+FROM postgres:14
-RUN apt-get update
+RUN apt-get update
RUN apt-get install --assume-yes --no-install-recommends --no-install-suggests \
bison \
build-essential \
flex \
- postgresql-server-dev-12
+ postgresql-server-dev-14
-COPY . /age
-RUN cd /age && make install
+COPY . /age
+RUN cd /age && make install
COPY docker-entrypoint-initdb.d/00-create-extension-age.sql /docker-entrypoint-initdb.d/00-create-extension-age.sql
diff --git a/Makefile b/Makefile
index f8b1369..3129315 100644
--- a/Makefile
+++ b/Makefile
@@ -17,8 +17,6 @@
MODULE_big = age
-
-
OBJS = src/backend/age.o \
src/backend/catalog/ag_catalog.o \
src/backend/catalog/ag_graph.o \
@@ -124,3 +122,5 @@ src/backend/parser/cypher_parser.o: src/backend/parser/cypher_gram.c
src/backend/parser/cypher_keywords.o: src/backend/parser/cypher_gram.c
src/backend/parser/ag_scanner.c: FLEX_NO_BACKUP=yes
+
+installcheck: export LC_COLLATE=C
diff --git a/README.md b/README.md
index 2854963..3fae411 100644
--- a/README.md
+++ b/README.md
@@ -20,18 +20,19 @@ Intelligent -- AGE allows you to perform graph queries that are the basis for ma
## Overview
-- **Apache AGE is currently being developed for the PostgreSQL 11 release** and will support PostgreSQL 12, 13 and all the future releases of PostgreSQL.
+**This README file is for the Apache AGE PostgreSQL 14 release**
+
+- **Apache AGE is currently being developed for the PostgreSQL 11, 12 and 14 releases** and will support all the future releases of PostgreSQL.
- Apache AGE supports the openCypher graph query language.
- Apache AGE enables querying multiple graphs at the same time.
- Apache AGE will be enhanced with an aim to support all of the key features of AgensGraph (PostgreSQL fork extended with graph DB functionality).
## Latest happenings
-- Latest Apache AGE release, [Apache AGE 1.0.0 (https://github.com/apache/age/releases/tag/v1.1.0-rc1).
+- Latest Apache AGE for PG 12 release, [Apache AGE 1.1.0 (https://github.com/apache/age/releases/tag/PG12/v1.1.0-rc0).
- The latest Apache AGE documentation is now available at [here](https://age.apache.org/docs/master/index.html).
- The roadmap has been updated, please check out the [Apache AGE website](http://age.apache.org/).
- Send all your comments and inquiries to the user mailing list, users@age.apache.org.
-- To focus more on implementing the openCypher specification, the support for PostgreSQL 12 will be added in the Q1 2022.
## Installation
diff --git a/RELEASE b/RELEASE
index a836997..5265b7d 100644
--- a/RELEASE
+++ b/RELEASE
@@ -15,9 +15,9 @@
# specific language governing permissions and limitations
# under the License.
-Release Notes for Apache AGE release v1.1.0
+Release Notes for Apache AGE release v1.1.0 for PG 12
-Apache AGE 1.1.0 - Release Notes
+Apache AGE 1.1.0 - Release Notes
Support for Agtype containment ops and GIN Indices.
Add CALL [YIELD] grammar rules for the implementation of CALL procedures.
diff --git a/regress/expected/expr.out b/regress/expected/expr.out
index 5142cb1..7fc8c3b 100644
--- a/regress/expected/expr.out
+++ b/regress/expected/expr.out
@@ -1466,11 +1466,19 @@ ERROR: invalid input syntax for type numeric: "2:71"
SELECT * FROM cypher('expr', $$
RETURN ('inf'::numeric)::numeric
$$) AS r(result agtype);
-ERROR: invalid input syntax for type numeric: "inf"
+ result
+-------------------
+ Infinity::numeric
+(1 row)
+
SELECT * FROM cypher('expr', $$
RETURN ('infinity'::numeric)::numeric
$$) AS r(result agtype);
-ERROR: invalid input syntax for type numeric: "infinity"
+ result
+-------------------
+ Infinity::numeric
+(1 row)
+
-- verify that output can be accepted and reproduced correctly via agtype_in
SELECT agtype_in('2.71::numeric');
agtype_in
diff --git a/src/backend/catalog/ag_catalog.c b/src/backend/catalog/ag_catalog.c
index e74be5a..f7ed249 100644
--- a/src/backend/catalog/ag_catalog.c
+++ b/src/backend/catalog/ag_catalog.c
@@ -39,10 +39,10 @@ static bool prev_object_hook_is_set;
static void object_access(ObjectAccessType access, Oid class_id, Oid object_id,
int sub_id, void *arg);
-void ag_ProcessUtility_hook(PlannedStmt *pstmt, const char *queryString,
+void ag_ProcessUtility_hook(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree,
ProcessUtilityContext context, ParamListInfo params,
QueryEnvironment *queryEnv, DestReceiver *dest,
- char *completionTag);
+ QueryCompletion *qc);
static bool is_age_drop(PlannedStmt *pstmt);
static void drop_age_extension(DropStmt *stmt);
@@ -86,19 +86,19 @@ void process_utility_hook_fini(void)
* from being thrown, we need to disable the object_access_hook before dropping
* the extension.
*/
-void ag_ProcessUtility_hook(PlannedStmt *pstmt, const char *queryString,
+void ag_ProcessUtility_hook(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree,
ProcessUtilityContext context, ParamListInfo params,
QueryEnvironment *queryEnv, DestReceiver *dest,
- char *completionTag)
+ QueryCompletion *qc)
{
if (is_age_drop(pstmt))
drop_age_extension((DropStmt *)pstmt->utilityStmt);
else if (prev_process_utility_hook)
- (*prev_process_utility_hook) (pstmt, queryString, context, params,
- queryEnv, dest, completionTag);
+ (*prev_process_utility_hook) (pstmt, queryString, readOnlyTree, context, params,
+ queryEnv, dest, qc);
else
- standard_ProcessUtility(pstmt, queryString, context, params, queryEnv,
- dest, completionTag);
+ standard_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, queryEnv,
+ dest, qc);
}
static void drop_age_extension(DropStmt *stmt)
diff --git a/src/backend/commands/label_commands.c b/src/backend/commands/label_commands.c
index c682d39..e8e2789 100644
--- a/src/backend/commands/label_commands.c
+++ b/src/backend/commands/label_commands.c
@@ -363,7 +363,7 @@ static void create_table_for_label(char *graph_name, char *label_name,
wrapper->stmt_location = -1;
wrapper->stmt_len = 0;
- ProcessUtility(wrapper, "(generated CREATE TABLE command)",
+ ProcessUtility(wrapper, "(generated CREATE TABLE command)", false,
PROCESS_UTILITY_SUBCOMMAND, NULL, NULL, None_Receiver,
NULL);
// CommandCounterIncrement() is called in ProcessUtility()
@@ -510,7 +510,7 @@ static FuncCall *build_id_default_func_expr(char *graph_name, char *label_name,
label_name_const->val.val.str = label_name;
label_name_const->location = -1;
label_id_func_args = list_make2(graph_name_const, label_name_const);
- label_id_func = makeFuncCall(label_id_func_name, label_id_func_args, -1);
+ label_id_func = makeFuncCall(label_id_func_name, label_id_func_args, COERCE_SQL_SYNTAX, -1);
//Build a node that will get the next val from the label's sequence
nextval_func_name = SystemFuncName("nextval");
@@ -524,7 +524,7 @@ static FuncCall *build_id_default_func_expr(char *graph_name, char *label_name,
regclass_cast->arg = (Node *)qualified_seq_name_const;
regclass_cast->location = -1;
nextval_func_args = list_make1(regclass_cast);
- nextval_func = makeFuncCall(nextval_func_name, nextval_func_args, -1);
+ nextval_func = makeFuncCall(nextval_func_name, nextval_func_args, COERCE_SQL_SYNTAX, -1);
/*
* Build a node that contructs the graphid from the label id function
@@ -533,7 +533,7 @@ static FuncCall *build_id_default_func_expr(char *graph_name, char *label_name,
graphid_func_name = list_make2(makeString("ag_catalog"),
makeString("_graphid"));
graphid_func_args = list_make2(label_id_func, nextval_func);
- graphid_func = makeFuncCall(graphid_func_name, graphid_func_args, -1);
+ graphid_func = makeFuncCall(graphid_func_name, graphid_func_args, COERCE_SQL_SYNTAX, -1);
return graphid_func;
}
@@ -581,7 +581,7 @@ static Constraint *build_properties_default(void)
// "ag_catalog"."agtype_build_map"()
func_name = list_make2(makeString("ag_catalog"),
makeString("agtype_build_map"));
- func = makeFuncCall(func_name, NIL, -1);
+ func = makeFuncCall(func_name, NIL, COERCE_SQL_SYNTAX, -1);
props_default = makeNode(Constraint);
props_default->contype = CONSTR_DEFAULT;
@@ -605,6 +605,7 @@ static void change_label_id_default(char *graph_name, char *label_name,
AlterTableCmd *tbl_cmd;
RangeVar *rv;
FuncCall *func_call;
+ AlterTableUtilityContext atuc;
func_call = build_id_default_func_expr(graph_name, label_name, schema_name,
seq_name);
@@ -625,7 +626,11 @@ static void change_label_id_default(char *graph_name, char *label_name,
tbl_stmt->cmds = list_make1(tbl_cmd);
- AlterTable(relid, AccessExclusiveLock, tbl_stmt);
+ atuc.relid = relid;
+ atuc.queryEnv = pstate->p_queryEnv;
+ atuc.queryString = pstate->p_sourcetext;
+
+ AlterTable(tbl_stmt, AccessExclusiveLock, &atuc);
CommandCounterIncrement();
}
diff --git a/src/backend/executor/cypher_create.c b/src/backend/executor/cypher_create.c
index ca4f177..fd5983b 100644
--- a/src/backend/executor/cypher_create.c
+++ b/src/backend/executor/cypher_create.c
@@ -45,10 +45,10 @@ static void rescan_cypher_create(CustomScanState *node);
static void create_edge(cypher_create_custom_scan_state *css,
cypher_target_node *node, Datum prev_vertex_id,
- ListCell *next);
+ ListCell *next, List *list);
static Datum create_vertex(cypher_create_custom_scan_state *css,
- cypher_target_node *node, ListCell *next);
+ cypher_target_node *node, ListCell *next, List *list);
static void process_pattern(cypher_create_custom_scan_state *css);
@@ -160,7 +160,7 @@ static void process_pattern(cypher_create_custom_scan_state *css)
* Create the first vertex. The create_vertex function will
* create the rest of the path, if necessary.
*/
- create_vertex(css, lfirst(lc), lnext(lc));
+ create_vertex(css, lfirst(lc), lnext(path->target_nodes, lc), path->target_nodes);
/*
* If this path is a variable, take the list that was accumulated
@@ -318,13 +318,13 @@ Node *create_cypher_create_plan_state(CustomScan *cscan)
*/
static void create_edge(cypher_create_custom_scan_state *css,
cypher_target_node *node, Datum prev_vertex_id,
- ListCell *next)
+ ListCell *next, List *list)
{
bool isNull;
EState *estate = css->css.ss.ps.state;
ExprContext *econtext = css->css.ss.ps.ps_ExprContext;
ResultRelInfo *resultRelInfo = node->resultRelInfo;
- ResultRelInfo *old_estate_es_result_relation_info = NULL;
+ ResultRelInfo **old_estate_es_result_relations_info = NULL;
TupleTableSlot *elemTupleSlot = node->elemTupleSlot;
TupleTableSlot *scanTupleSlot = econtext->ecxt_scantuple;
Datum id;
@@ -339,7 +339,7 @@ static void create_edge(cypher_create_custom_scan_state *css,
* next vertex's id.
*/
css->path_values = NIL;
- next_vertex_id = create_vertex(css, lfirst(next), lnext(next));
+ next_vertex_id = create_vertex(css, lfirst(next), lnext(list, next), list);
/*
* Set the start and end vertex ids
@@ -371,9 +371,9 @@ static void create_edge(cypher_create_custom_scan_state *css,
*/
/* save the old result relation info */
- old_estate_es_result_relation_info = estate->es_result_relation_info;
+ old_estate_es_result_relations_info = estate->es_result_relations;
- estate->es_result_relation_info = resultRelInfo;
+ estate->es_result_relations = &resultRelInfo;
ExecClearTuple(elemTupleSlot);
@@ -400,7 +400,7 @@ static void create_edge(cypher_create_custom_scan_state *css,
insert_entity_tuple(resultRelInfo, elemTupleSlot, estate);
/* restore the old result relation info */
- estate->es_result_relation_info = old_estate_es_result_relation_info;
+ estate->es_result_relations = old_estate_es_result_relations_info;
/*
* When the edge is used by clauses higher in the execution tree
@@ -437,7 +437,7 @@ static void create_edge(cypher_create_custom_scan_state *css,
* the create_edge function.
*/
static Datum create_vertex(cypher_create_custom_scan_state *css,
- cypher_target_node *node, ListCell *next)
+ cypher_target_node *node, ListCell *next, List *list)
{
bool isNull;
Datum id;
@@ -456,7 +456,7 @@ static Datum create_vertex(cypher_create_custom_scan_state *css,
*/
if (CYPHER_TARGET_NODE_INSERT_ENTITY(node->flags))
{
- ResultRelInfo *old_estate_es_result_relation_info = NULL;
+ ResultRelInfo **old_estate_es_result_relations_info = NULL;
/*
* Set estate's result relation to the vertex's result
@@ -466,9 +466,9 @@ static Datum create_vertex(cypher_create_custom_scan_state *css,
*/
/* save the old result relation info */
- old_estate_es_result_relation_info = estate->es_result_relation_info;
+ old_estate_es_result_relations_info = estate->es_result_relations;
- estate->es_result_relation_info = resultRelInfo;
+ estate->es_result_relations = &resultRelInfo;
ExecClearTuple(elemTupleSlot);
@@ -487,7 +487,7 @@ static Datum create_vertex(cypher_create_custom_scan_state *css,
insert_entity_tuple(resultRelInfo, elemTupleSlot, estate);
/* restore the old result relation info */
- estate->es_result_relation_info = old_estate_es_result_relation_info;
+ estate->es_result_relations = old_estate_es_result_relations_info;
/*
* When the vertex is used by clauses higher in the execution tree
@@ -586,7 +586,7 @@ static Datum create_vertex(cypher_create_custom_scan_state *css,
// If the path continues, create the next edge, passing the vertex's id.
if (next != NULL)
{
- create_edge(css, lfirst(next), id, lnext(next));
+ create_edge(css, lfirst(next), id, lnext(list, next), list);
}
return id;
diff --git a/src/backend/executor/cypher_delete.c b/src/backend/executor/cypher_delete.c
index 7bb7c07..2819717 100644
--- a/src/backend/executor/cypher_delete.c
+++ b/src/backend/executor/cypher_delete.c
@@ -279,7 +279,7 @@ static agtype_value *extract_entity(CustomScanState *node,
static void delete_entity(EState *estate, ResultRelInfo *resultRelInfo,
HeapTuple tuple)
{
- ResultRelInfo *saved_resultRelInfo;
+ ResultRelInfo **saved_resultRelsInfo;
LockTupleMode lockmode;
TM_FailureData hufd;
TM_Result lock_result;
@@ -287,8 +287,8 @@ static void delete_entity(EState *estate, ResultRelInfo *resultRelInfo,
Buffer buffer;
// Find the physical tuple, this variable is coming from
- saved_resultRelInfo = estate->es_result_relation_info;
- estate->es_result_relation_info = resultRelInfo;
+ saved_resultRelsInfo = estate->es_result_relations;
+ estate->es_result_relations = &resultRelInfo;
lockmode = ExecUpdateLockMode(estate, resultRelInfo);
@@ -352,7 +352,7 @@ static void delete_entity(EState *estate, ResultRelInfo *resultRelInfo,
ReleaseBuffer(buffer);
- estate->es_result_relation_info = saved_resultRelInfo;
+ estate->es_result_relations = saved_resultRelsInfo;
}
/*
diff --git a/src/backend/executor/cypher_merge.c b/src/backend/executor/cypher_merge.c
index fbfce8f..b8b779d 100644
--- a/src/backend/executor/cypher_merge.c
+++ b/src/backend/executor/cypher_merge.c
@@ -42,10 +42,10 @@ static TupleTableSlot *exec_cypher_merge(CustomScanState *node);
static void end_cypher_merge(CustomScanState *node);
static void rescan_cypher_merge(CustomScanState *node);
static Datum merge_vertex(cypher_merge_custom_scan_state *css,
- cypher_target_node *node, ListCell *next);
+ cypher_target_node *node, ListCell *next, List* list);
static void merge_edge(cypher_merge_custom_scan_state *css,
cypher_target_node *node, Datum prev_vertex_id,
- ListCell *next);
+ ListCell *next, List *list);
static void process_simple_merge(CustomScanState *node);
static bool check_path(cypher_merge_custom_scan_state *css,
TupleTableSlot *slot);
@@ -221,7 +221,7 @@ static void process_path(cypher_merge_custom_scan_state *css)
* Create the first vertex. The create_vertex function will
* create the rest of the path, if necessary.
*/
- merge_vertex(css, lfirst(lc), lnext(lc));
+ merge_vertex(css, lfirst(lc), lnext(path->target_nodes, lc), path->target_nodes);
/*
@@ -615,7 +615,7 @@ Node *create_cypher_merge_plan_state(CustomScan *cscan)
* the create_edge function.
*/
static Datum merge_vertex(cypher_merge_custom_scan_state *css,
- cypher_target_node *node, ListCell *next)
+ cypher_target_node *node, ListCell *next, List *list)
{
bool isNull;
Datum id;
@@ -634,7 +634,7 @@ static Datum merge_vertex(cypher_merge_custom_scan_state *css,
*/
if (CYPHER_TARGET_NODE_INSERT_ENTITY(node->flags))
{
- ResultRelInfo *old_estate_es_result_relation_info = NULL;
+ ResultRelInfo **old_estate_es_result_relations_info = NULL;
Datum prop;
/*
* Set estate's result relation to the vertex's result
@@ -644,9 +644,9 @@ static Datum merge_vertex(cypher_merge_custom_scan_state *css,
*/
/* save the old result relation info */
- old_estate_es_result_relation_info = estate->es_result_relation_info;
+ old_estate_es_result_relations_info = estate->es_result_relations;
- estate->es_result_relation_info = resultRelInfo;
+ estate->es_result_relations = &resultRelInfo;
ExecClearTuple(elemTupleSlot);
@@ -703,7 +703,7 @@ static Datum merge_vertex(cypher_merge_custom_scan_state *css,
}
/* restore the old result relation info */
- estate->es_result_relation_info = old_estate_es_result_relation_info;
+ estate->es_result_relations = old_estate_es_result_relations_info;
/*
* When the vertex is used by clauses higher in the execution tree
@@ -811,7 +811,7 @@ static Datum merge_vertex(cypher_merge_custom_scan_state *css,
/* If the path continues, create the next edge, passing the vertex's id. */
if (next != NULL)
{
- merge_edge(css, lfirst(next), id, lnext(next));
+ merge_edge(css, lfirst(next), id, lnext(list, next), list);
}
return id;
@@ -822,13 +822,13 @@ static Datum merge_vertex(cypher_merge_custom_scan_state *css,
*/
static void merge_edge(cypher_merge_custom_scan_state *css,
cypher_target_node *node, Datum prev_vertex_id,
- ListCell *next)
+ ListCell *next, List *list)
{
bool isNull;
EState *estate = css->css.ss.ps.state;
ExprContext *econtext = css->css.ss.ps.ps_ExprContext;
ResultRelInfo *resultRelInfo = node->resultRelInfo;
- ResultRelInfo *old_estate_es_result_relation_info = NULL;
+ ResultRelInfo **old_estate_es_result_relations_info = NULL;
TupleTableSlot *elemTupleSlot = node->elemTupleSlot;
Datum id;
Datum start_id, end_id, next_vertex_id;
@@ -843,7 +843,7 @@ static void merge_edge(cypher_merge_custom_scan_state *css,
* next vertex's id.
*/
css->path_values = NIL;
- next_vertex_id = merge_vertex(css, lfirst(next), lnext(next));
+ next_vertex_id = merge_vertex(css, lfirst(next), lnext(list, next), list);
/*
* Set the start and end vertex ids
@@ -875,9 +875,9 @@ static void merge_edge(cypher_merge_custom_scan_state *css,
*/
/* save the old result relation info */
- old_estate_es_result_relation_info = estate->es_result_relation_info;
+ old_estate_es_result_relations_info = estate->es_result_relations;
- estate->es_result_relation_info = resultRelInfo;
+ estate->es_result_relations = &resultRelInfo;
ExecClearTuple(elemTupleSlot);
@@ -903,7 +903,7 @@ static void merge_edge(cypher_merge_custom_scan_state *css,
insert_entity_tuple(resultRelInfo, elemTupleSlot, estate);
/* restore the old result relation info */
- estate->es_result_relation_info = old_estate_es_result_relation_info;
+ estate->es_result_relations = old_estate_es_result_relations_info;
/*
* When the edge is used by clauses higher in the execution tree
diff --git a/src/backend/executor/cypher_set.c b/src/backend/executor/cypher_set.c
index 73ce1fa..4079680 100644
--- a/src/backend/executor/cypher_set.c
+++ b/src/backend/executor/cypher_set.c
@@ -114,8 +114,8 @@ static HeapTuple update_entity_tuple(ResultRelInfo *resultRelInfo,
bool update_indexes;
TM_Result result;
- ResultRelInfo *saved_resultRelInfo = estate->es_result_relation_info;
- estate->es_result_relation_info = resultRelInfo;
+ ResultRelInfo **saved_resultRelsInfo = estate->es_result_relations;
+ estate->es_result_relations = &resultRelInfo;
lockmode = ExecUpdateLockMode(estate, resultRelInfo);
@@ -156,7 +156,7 @@ static HeapTuple update_entity_tuple(ResultRelInfo *resultRelInfo,
}
ExecCloseIndices(resultRelInfo);
- estate->es_result_relation_info = saved_resultRelInfo;
+ estate->es_result_relations = saved_resultRelsInfo;
return tuple;
}
@@ -170,7 +170,7 @@ static HeapTuple update_entity_tuple(ResultRelInfo *resultRelInfo,
// Insert index entries for the tuple
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
{
- ExecInsertIndexTuples(elemTupleSlot, estate, false, NULL, NIL);
+ ExecInsertIndexTuples(resultRelInfo, elemTupleSlot, estate, false, false, NULL, NIL);
}
ExecCloseIndices(resultRelInfo);
@@ -192,7 +192,7 @@ static HeapTuple update_entity_tuple(ResultRelInfo *resultRelInfo,
ReleaseBuffer(buffer);
- estate->es_result_relation_info = saved_resultRelInfo;
+ estate->es_result_relations = saved_resultRelsInfo;
return tuple;
}
@@ -597,12 +597,12 @@ static void process_update_list(CustomScanState *node)
static TupleTableSlot *exec_cypher_set(CustomScanState *node)
{
cypher_set_custom_scan_state *css = (cypher_set_custom_scan_state *)node;
- ResultRelInfo *saved_resultRelInfo;
+ ResultRelInfo **saved_resultRelsInfo;
EState *estate = css->css.ss.ps.state;
ExprContext *econtext = css->css.ss.ps.ps_ExprContext;
TupleTableSlot *slot;
- saved_resultRelInfo = estate->es_result_relation_info;
+ saved_resultRelsInfo = estate->es_result_relations;
//Process the subtree first
Decrement_Estate_CommandId(estate);
@@ -619,7 +619,7 @@ static TupleTableSlot *exec_cypher_set(CustomScanState *node)
if (CYPHER_CLAUSE_IS_TERMINAL(css->flags))
{
- estate->es_result_relation_info = saved_resultRelInfo;
+ estate->es_result_relations = saved_resultRelsInfo;
process_all_tuples(node);
@@ -634,7 +634,7 @@ static TupleTableSlot *exec_cypher_set(CustomScanState *node)
/* increment the command counter to reflect the updates */
CommandCounterIncrement();
- estate->es_result_relation_info = saved_resultRelInfo;
+ estate->es_result_relations = saved_resultRelsInfo;
econtext->ecxt_scantuple = ExecProject(node->ss.ps.lefttree->ps_ProjInfo);
diff --git a/src/backend/executor/cypher_utils.c b/src/backend/executor/cypher_utils.c
index 7b92fbc..16eb088 100644
--- a/src/backend/executor/cypher_utils.c
+++ b/src/backend/executor/cypher_utils.c
@@ -254,7 +254,7 @@ HeapTuple insert_entity_tuple_cid(ResultRelInfo *resultRelInfo,
// Insert index entries for the tuple
if (resultRelInfo->ri_NumIndices > 0)
{
- ExecInsertIndexTuples(elemTupleSlot, estate, false, NULL, NIL);
+ ExecInsertIndexTuples(resultRelInfo, elemTupleSlot, estate, false, false, NULL, NIL);
}
return tuple;
diff --git a/src/backend/parser/ag_scanner.l b/src/backend/parser/ag_scanner.l
index 68b15a2..18ce042 100644
--- a/src/backend/parser/ag_scanner.l
+++ b/src/backend/parser/ag_scanner.l
@@ -284,8 +284,6 @@ static uint32 octdigit_value(const char c);
static bool is_high_surrogate(const pg_wchar c);
static bool is_low_surrogate(const pg_wchar c);
-static pg_wchar surrogate_pair_to_codepoint(const pg_wchar hi,
- const pg_wchar lo);
#define update_location() \
do \
@@ -1099,15 +1097,6 @@ static bool is_low_surrogate(const pg_wchar c)
return (c >= 0xDC00 && c <= 0xDFFF);
}
-// http://www.unicode.org/faq/utf_bom.html#utf16-4
-static pg_wchar surrogate_pair_to_codepoint(const pg_wchar hi,
- const pg_wchar lo)
-{
- const pg_wchar surrogate_offset = 0x10000 - (0xD800 << 10) - 0xDC00;
-
- return (hi << 10) + lo + surrogate_offset;
-}
-
static int _scan_errmsg(const char *msg, const ag_yy_extra *extra)
{
const char *t = extra->scan_buf + extra->last_loc;
diff --git a/src/backend/parser/cypher_analyze.c b/src/backend/parser/cypher_analyze.c
index 9ffb863..d6ba51f 100644
--- a/src/backend/parser/cypher_analyze.c
+++ b/src/backend/parser/cypher_analyze.c
@@ -38,6 +38,7 @@
#include "nodes/ag_nodes.h"
#include "parser/cypher_analyze.h"
#include "parser/cypher_clause.h"
+#include "parser/cypher_item.h"
#include "parser/cypher_parse_node.h"
#include "parser/cypher_parser.h"
#include "utils/ag_func.h"
@@ -47,7 +48,7 @@ static Node *extra_node = NULL;
static post_parse_analyze_hook_type prev_post_parse_analyze_hook;
-static void post_parse_analyze(ParseState *pstate, Query *query);
+static void post_parse_analyze(ParseState *pstate, Query *query, JumbleState *jstate);
static bool convert_cypher_walker(Node *node, ParseState *pstate);
static bool is_rte_cypher(RangeTblEntry *rte);
static bool is_func_cypher(FuncExpr *funcexpr);
@@ -75,10 +76,10 @@ void post_parse_analyze_fini(void)
post_parse_analyze_hook = prev_post_parse_analyze_hook;
}
-static void post_parse_analyze(ParseState *pstate, Query *query)
+static void post_parse_analyze(ParseState *pstate, Query *query, JumbleState *jstate)
{
if (prev_post_parse_analyze_hook)
- prev_post_parse_analyze_hook(pstate, query);
+ prev_post_parse_analyze_hook(pstate, query, jstate);
convert_cypher_walker((Node *)query, pstate);
}
@@ -277,6 +278,7 @@ static void convert_cypher_to_subquery(RangeTblEntry *rte, ParseState *pstate)
errpos_ecb_state ecb_state;
List *stmt;
Query *query;
+ List *list;
/*
* We cannot apply this feature directly to SELECT subquery because the
@@ -379,13 +381,15 @@ static void convert_cypher_to_subquery(RangeTblEntry *rte, ParseState *pstate)
if (extra_node == NULL)
{
extra_node = llast(stmt);
- list_delete_ptr(stmt, extra_node);
+ list = list_delete_ptr(stmt, extra_node);
+ Assert(!list_member_ptr(list, extra_node));
}
else
{
Node *temp = llast(stmt);
- list_delete_ptr(stmt, temp);
+ list = list_delete_ptr(stmt, temp);
+ Assert(!list_member_ptr(list, temp));
}
cancel_errpos_ecb(&ecb_state);
@@ -570,7 +574,7 @@ static Query *analyze_cypher_and_coerce(List *stmt, RangeTblFunction *rtfunc,
Query *query;
const bool lateral = false;
Query *subquery;
- RangeTblEntry *rte;
+ ParseNamespaceItem *pnsi;
int rtindex;
ListCell *lt;
ListCell *lc1;
@@ -617,13 +621,15 @@ static Query *analyze_cypher_and_coerce(List *stmt, RangeTblFunction *rtfunc,
parser_errposition(pstate, exprLocation(rtfunc->funcexpr))));
}
- rte = addRangeTableEntryForSubquery(pstate, subquery, makeAlias("_", NIL),
+ pnsi = addRangeTableEntryForSubquery(pstate, subquery, makeAlias("_", NIL),
lateral, true);
+
rtindex = list_length(pstate->p_rtable);
Assert(rtindex == 1); // rte is the only RangeTblEntry in pstate
- addRTEtoQuery(pstate, rte, true, true, true);
- query->targetList = expandRelAttrs(pstate, rte, rtindex, 0, -1);
+ addNSItemToQuery(pstate, pnsi, true, true, true);
+
+ query->targetList = expandNSItemAttrs(pstate, pnsi, 0, -1);
markTargetListOrigins(pstate, query->targetList);
@@ -673,9 +679,9 @@ static Query *analyze_cypher_and_coerce(List *stmt, RangeTblFunction *rtfunc,
te->expr = (Expr *)new_expr;
}
- lc1 = lnext(lc1);
- lc2 = lnext(lc2);
- lc3 = lnext(lc3);
+ lc1 = lnext(rtfunc->funccolnames, lc1);
+ lc2 = lnext(rtfunc->funccoltypes, lc2);
+ lc3 = lnext(rtfunc->funccoltypmods, lc3);
}
query->rtable = pstate->p_rtable;
@@ -686,4 +692,4 @@ static Query *analyze_cypher_and_coerce(List *stmt, RangeTblFunction *rtfunc,
free_parsestate(pstate);
return query;
-}
+}
\ No newline at end of file
diff --git a/src/backend/parser/cypher_clause.c b/src/backend/parser/cypher_clause.c
index e07d07a..78ee171 100644
--- a/src/backend/parser/cypher_clause.c
+++ b/src/backend/parser/cypher_clause.c
@@ -141,9 +141,9 @@ static Expr *transform_cypher_edge(cypher_parsestate *cpstate,
static Expr *transform_cypher_node(cypher_parsestate *cpstate,
cypher_node *node, List **target_list,
bool output_node);
-static Node *make_vertex_expr(cypher_parsestate *cpstate, RangeTblEntry *rte,
+static Node *make_vertex_expr(cypher_parsestate *cpstate, ParseNamespaceItem *pnsi,
char *label);
-static Node *make_edge_expr(cypher_parsestate *cpstate, RangeTblEntry *rte,
+static Node *make_edge_expr(cypher_parsestate *cpstate, ParseNamespaceItem *pnsi,
char *label);
static Node *make_qual(cypher_parsestate *cpstate,
transform_entity *entity, char *name);
@@ -238,8 +238,8 @@ Query *cypher_parse_sub_analyze_union(cypher_clause *clause,
CommonTableExpr *parentCTE,
bool locked_from_parent,
bool resolve_unknowns);
-static void get_res_cols(ParseState *pstate, RangeTblEntry *l_rte,
- RangeTblEntry *r_rte, List **res_colnames,
+static void get_res_cols(ParseState *pstate, ParseNamespaceItem *l_pnsi,
+ ParseNamespaceItem *r_pnsi, List **res_colnames,
List **res_colvars);
// unwind
static Query *transform_cypher_unwind(cypher_parsestate *cpstate,
@@ -276,7 +276,7 @@ transform_cypher_merge_mark_tuple_position(List *target_list,
#define transform_prev_cypher_clause(cpstate, prev_clause, add_rte_to_query) \
transform_cypher_clause_as_subquery(cpstate, transform_cypher_clause, \
prev_clause, NULL, add_rte_to_query)
-static RangeTblEntry *transform_cypher_clause_as_subquery(cypher_parsestate *cpstate,
+static ParseNamespaceItem *transform_cypher_clause_as_subquery(cypher_parsestate *cpstate,
transform_method transform,
cypher_clause *clause,
Alias *alias,
@@ -302,26 +302,27 @@ static List *add_target_to_group_list(cypher_parsestate *cpstate,
List *targetlist, int location);
static void advance_transform_entities_to_next_clause(List *entities);
-static ParseNamespaceItem *create_namespace_item(RangeTblEntry *rte, bool p_rel_visible,
- bool p_cols_visible, bool p_lateral_only,
- bool p_lateral_ok);
+static ParseNamespaceItem *get_namespace_item(ParseState *pstate,
+ RangeTblEntry *rte);
static List *make_target_list_from_join(ParseState *pstate,
RangeTblEntry *rte);
static Expr *add_volatile_wrapper(Expr *node);
static FuncExpr *make_clause_func_expr(char *function_name,
Node *clause_information);
/* for VLE support */
-static RangeTblEntry *transform_RangeFunction(cypher_parsestate *cpstate,
+static ParseNamespaceItem *transform_RangeFunction(cypher_parsestate *cpstate,
RangeFunction *r);
static Node *transform_VLE_Function(cypher_parsestate *cpstate, Node *n,
RangeTblEntry **top_rte, int *top_rti,
List **namespace);
-static RangeTblEntry *append_VLE_Func_to_FromClause(cypher_parsestate *cpstate,
+static ParseNamespaceItem *append_VLE_Func_to_FromClause(cypher_parsestate *cpstate,
Node *n);
static void setNamespaceLateralState(List *namespace, bool lateral_only,
bool lateral_ok);
static bool isa_special_VLE_case(cypher_path *path);
+ParseNamespaceItem *find_pnsi(cypher_parsestate *cpstate, char *varname);
+
/*
* transform a cypher_clause
*/
@@ -455,8 +456,10 @@ static Query *transform_cypher_union(cypher_parsestate *cpstate,
ListCell *left_tlist, *lct, *lcm, *lcc;
List *targetvars, *targetnames, *sv_namespace;
int sv_rtable_length;
- RangeTblEntry *jrte;
int tllen;
+ ParseNamespaceItem *nsitem;
+ ParseNamespaceColumn *sortnscolumns;
+ int sortcolindex;
qry->commandType = CMD_SELECT;
@@ -517,11 +520,14 @@ static Query *transform_cypher_union(cypher_parsestate *cpstate,
qry->targetList = NIL;
targetvars = NIL;
targetnames = NIL;
- left_tlist = list_head(leftmostQuery->targetList);
+ sortnscolumns = (ParseNamespaceColumn *)
+ palloc0(list_length(cypher_union_statement->colTypes) * sizeof(ParseNamespaceColumn));
+ sortcolindex = 0;
- forthree(lct, cypher_union_statement->colTypes,
+ forfour(lct, cypher_union_statement->colTypes,
lcm, cypher_union_statement->colTypmods,
- lcc, cypher_union_statement->colCollations)
+ lcc, cypher_union_statement->colCollations,
+ left_tlist, leftmostQuery->targetList)
{
Oid colType = lfirst_oid(lct);
int32 colTypmod = lfirst_int(lcm);
@@ -547,7 +553,14 @@ static Query *transform_cypher_union(cypher_parsestate *cpstate,
qry->targetList = lappend(qry->targetList, tle);
targetvars = lappend(targetvars, var);
targetnames = lappend(targetnames, makeString(colName));
- left_tlist = lnext(left_tlist);
+ sortnscolumns[sortcolindex].p_varno = leftmostRTI;
+ sortnscolumns[sortcolindex].p_varattno = lefttle->resno;
+ sortnscolumns[sortcolindex].p_vartype = colType;
+ sortnscolumns[sortcolindex].p_vartypmod = colTypmod;
+ sortnscolumns[sortcolindex].p_varcollid = colCollation;
+ sortnscolumns[sortcolindex].p_varnosyn = leftmostRTI;
+ sortnscolumns[sortcolindex].p_varattnosyn = lefttle->resno;
+ sortcolindex++;
}
/*
@@ -562,18 +575,15 @@ static Query *transform_cypher_union(cypher_parsestate *cpstate,
*/
sv_rtable_length = list_length(pstate->p_rtable);
- jrte = addRangeTableEntryForJoin(pstate,
- targetnames,
- JOIN_INNER,
- targetvars,
- NULL,
- false);
+ nsitem = addRangeTableEntryForJoin(pstate, targetnames, sortnscolumns,
+ JOIN_INNER, 0, targetvars, NIL, NIL,
+ NULL, NULL, false);
sv_namespace = pstate->p_namespace;
pstate->p_namespace = NIL;
/* add jrte to column namespace only */
- addRTEtoQuery(pstate, jrte, false, false, true);
+ addNSItemToQuery(pstate, nsitem, false, false, true);
tllen = list_length(qry->targetList);
@@ -643,6 +653,7 @@ transform_cypher_union_tree(cypher_parsestate *cpstate, cypher_clause *clause,
ParseState *pstate = (ParseState *)cpstate;
cypher_return *cmp;
+ ParseNamespaceItem *pnsi;
/* Guard against stack overflow due to overly complex set-expressions */
check_stack_depth();
@@ -760,12 +771,12 @@ transform_cypher_union_tree(cypher_parsestate *cpstate, cypher_clause *clause,
*/
snprintf(returnName, sizeof(returnName), "*SELECT* %d ",
list_length(pstate->p_rtable) + 1);
- rte = addRangeTableEntryForSubquery(pstate,
+ pnsi = addRangeTableEntryForSubquery(pstate,
returnQuery,
makeAlias(returnName, NIL),
false,
false);
-
+ rte = pnsi->p_rte;
rtr = makeNode(RangeTblRef);
/* assume new rte is at end */
rtr->rtindex = list_length(pstate->p_rtable);
@@ -1088,19 +1099,19 @@ static Query *transform_cypher_unwind(cypher_parsestate *cpstate,
ParseExprKind old_expr_kind;
Node *funcexpr;
TargetEntry *te;
+ ParseNamespaceItem *pnsi;
query = makeNode(Query);
query->commandType = CMD_SELECT;
if (clause->prev)
{
- RangeTblEntry *rte;
int rtindex;
- rte = transform_prev_cypher_clause(cpstate, clause->prev, true);
+ pnsi = transform_prev_cypher_clause(cpstate, clause->prev, true);
rtindex = list_length(pstate->p_rtable);
Assert(rtindex == 1); // rte is the first RangeTblEntry in pstate
- query->targetList = expandRelAttrs(pstate, rte, rtindex, 0, -1);
+ query->targetList = expandNSItemAttrs(pstate, pnsi, 0, -1);
}
target_syntax_loc = exprLocation((const Node *) self->target);
@@ -1115,7 +1126,7 @@ static Query *transform_cypher_unwind(cypher_parsestate *cpstate,
expr = transform_cypher_expr(cpstate, self->target->val, EXPR_KIND_SELECT_TARGET);
- unwind = makeFuncCall(list_make1(makeString("age_unnest")), NIL, -1);
+ unwind = makeFuncCall(list_make1(makeString("age_unnest")), NIL, COERCE_SQL_SYNTAX, -1);
old_expr_kind = pstate->p_expr_kind;
@@ -1941,18 +1952,18 @@ static Query *transform_cypher_clause_with_where(cypher_parsestate *cpstate,
if (where)
{
- RangeTblEntry *rte;
int rtindex;
+ ParseNamespaceItem *pnsi;
query = makeNode(Query);
query->commandType = CMD_SELECT;
- rte = transform_cypher_clause_as_subquery(cpstate, transform, clause, NULL, true);
-
+ pnsi = transform_cypher_clause_as_subquery(cpstate, transform, clause, NULL, true);
+ Assert(pnsi != NULL);
rtindex = list_length(pstate->p_rtable);
Assert(rtindex == 1); // rte is the only RangeTblEntry in pstate
- query->targetList = expandRelAttrs(pstate, rte, rtindex, 0, -1);
+ query->targetList = expandNSItemAttrs(pstate, pnsi, 0, -1);
markTargetListOrigins(pstate, query->targetList);
@@ -1991,17 +2002,15 @@ static Node *transform_clause_for_join(cypher_parsestate *cpstate,
ParseNamespaceItem **nsitem,
Alias* alias)
{
- ParseState *pstate = (ParseState *)cpstate;
RangeTblRef *rtr;
- *rte = transform_cypher_clause_as_subquery(cpstate,
+ *nsitem = transform_cypher_clause_as_subquery(cpstate,
transform_cypher_clause,
clause, alias, false);
-
- *nsitem = create_namespace_item(*rte, false, true, false, true);
+ *rte = (*nsitem)->p_rte;
rtr = makeNode(RangeTblRef);
- rtr->rtindex = RTERangeTablePosn(pstate, *rte, NULL);
+ rtr->rtindex = (*nsitem)->p_rtindex;
return (Node *) rtr;
}
@@ -2014,8 +2023,8 @@ static Node *transform_clause_for_join(cypher_parsestate *cpstate,
* variable declared in a previous clause (the l_rte). The output is the
* res_colnames and res_colvars that are passed in.
*/
-static void get_res_cols(ParseState *pstate, RangeTblEntry *l_rte,
- RangeTblEntry *r_rte, List **res_colnames,
+static void get_res_cols(ParseState *pstate, ParseNamespaceItem *l_pnsi,
+ ParseNamespaceItem *r_pnsi, List **res_colnames,
List **res_colvars)
{
List *l_colnames, *l_colvars;
@@ -2024,9 +2033,9 @@ static void get_res_cols(ParseState *pstate, RangeTblEntry *l_rte,
List *colnames = NIL;
List *colvars = NIL;
- expandRTE(l_rte, RTERangeTablePosn(pstate, l_rte, NULL), 0, -1, false,
+ expandRTE(l_pnsi->p_rte, l_pnsi->p_rtindex, 0, -1, false,
&l_colnames, &l_colvars);
- expandRTE(r_rte, RTERangeTablePosn(pstate, r_rte, NULL), 0, -1, false,
+ expandRTE(r_pnsi->p_rte, r_pnsi->p_rtindex, 0, -1, false,
&r_colnames, &r_colvars);
// add in all colnames and colvars from the l_rte.
@@ -2072,14 +2081,13 @@ static RangeTblEntry *transform_cypher_optional_match_clause(cypher_parsestate *
cypher_clause *clause)
{
cypher_clause *prevclause;
- RangeTblEntry *rte;
RangeTblEntry *l_rte, *r_rte;
ParseNamespaceItem *l_nsitem, *r_nsitem;
ParseState *pstate = (ParseState *) cpstate;
JoinExpr* j = makeNode(JoinExpr);
List *res_colnames = NIL, *res_colvars = NIL;
Alias *l_alias, *r_alias;
- ParseNamespaceItem *nsitem;
+ ParseNamespaceItem *jnsitem;
int i = 0;
j->jointype = JOIN_LEFT;
@@ -2117,12 +2125,21 @@ static RangeTblEntry *transform_cypher_optional_match_clause(cypher_parsestate *
pstate->p_namespace = NIL;
// get the colnames and colvars from the rtes
- get_res_cols(pstate, l_rte, r_rte, &res_colnames, &res_colvars);
-
- rte = addRangeTableEntryForJoin(pstate, res_colnames, j->jointype,
- res_colvars, j->alias, true);
-
- j->rtindex = RTERangeTablePosn(pstate, rte, NULL);
+ get_res_cols(pstate, l_nsitem, r_nsitem, &res_colnames, &res_colvars);
+
+ jnsitem = addRangeTableEntryForJoin(pstate,
+ res_colnames,
+ NULL,
+ j->jointype,
+ 0,
+ res_colvars,
+ NIL,
+ NIL,
+ j->alias,
+ NULL,
+ false);
+
+ j->rtindex = jnsitem->p_rtindex;
for (i = list_length(pstate->p_joinexprs) + 1; i < j->rtindex; i++)
{
@@ -2133,10 +2150,10 @@ static RangeTblEntry *transform_cypher_optional_match_clause(cypher_parsestate *
pstate->p_joinlist = lappend(pstate->p_joinlist, j);
- nsitem = create_namespace_item(rte, false, true, false, true);
- pstate->p_namespace = lappend(pstate->p_namespace, nsitem);
+ /* add jrte to column namespace only */
+ addNSItemToQuery(pstate, jnsitem, false, false, true);
- return rte;
+ return jnsitem->p_rte;
}
static Query *transform_cypher_match_pattern(cypher_parsestate *cpstate,
@@ -2165,8 +2182,10 @@ static Query *transform_cypher_match_pattern(cypher_parsestate *cpstate,
{
RangeTblEntry *rte;
int rtindex;
+ ParseNamespaceItem *pnsi;
- rte = transform_prev_cypher_clause(cpstate, clause->prev, true);
+ pnsi = transform_prev_cypher_clause(cpstate, clause->prev, true);
+ rte = pnsi->p_rte;
rtindex = list_length(pstate->p_rtable);
Assert(rtindex == 1); // rte is the first RangeTblEntry in pstate
@@ -2175,7 +2194,8 @@ static Query *transform_cypher_match_pattern(cypher_parsestate *cpstate,
* all the variables that are introduced in the previous clause to the
* next clause
*/
- query->targetList = expandRelAttrs(pstate, rte, rtindex, 0, -1);
+ pnsi = get_namespace_item(pstate, rte);
+ query->targetList = expandNSItemAttrs(pstate, pnsi, 0, -1);
}
transform_match_pattern(cpstate, query, self->pattern, where);
@@ -2223,18 +2243,22 @@ static List *make_target_list_from_join(ParseState *pstate, RangeTblEntry *rte)
/*
* Function to make a target list from an RTE. Borrowed from AgensGraph and PG
*/
-static List *makeTargetListFromRTE(ParseState *pstate, RangeTblEntry *rte)
+static List *makeTargetListFromPNSItem(ParseState *pstate, ParseNamespaceItem *pnsi)
{
List *targetlist = NIL;
int rtindex;
int varattno;
ListCell *ln;
ListCell *lt;
+ RangeTblEntry *rte;
+
+ Assert(pnsi->p_rte);
+ rte = pnsi->p_rte;
/* right now this is only for subqueries */
AssertArg(rte->rtekind == RTE_SUBQUERY);
- rtindex = RTERangeTablePosn(pstate, rte, NULL);
+ rtindex = pnsi->p_rtindex;
varattno = 1;
ln = list_head(rte->eref->colnames);
@@ -2265,7 +2289,7 @@ static List *makeTargetListFromRTE(ParseState *pstate, RangeTblEntry *rte)
targetlist = lappend(targetlist, tmp);
varattno++;
- ln = lnext(ln);
+ ln = lnext(rte->eref->colnames, ln);
}
return targetlist;
@@ -2281,10 +2305,9 @@ static Query *transform_cypher_sub_pattern(cypher_parsestate *cpstate,
cypher_match *match;
cypher_clause *c;
Query *qry;
- RangeTblEntry *rte;
ParseState *pstate = (ParseState *)cpstate;
cypher_sub_pattern *subpat = (cypher_sub_pattern*)clause->self;
-
+ ParseNamespaceItem *pnsi;
cypher_parsestate *child_parse_state = make_cypher_parsestate(cpstate);
ParseState *p_child_parse_state = (ParseState *) child_parse_state;
p_child_parse_state->p_expr_kind = pstate->p_expr_kind;
@@ -2303,11 +2326,11 @@ static Query *transform_cypher_sub_pattern(cypher_parsestate *cpstate,
qry = makeNode(Query);
qry->commandType = CMD_SELECT;
- rte = transform_cypher_clause_as_subquery(child_parse_state,
+ pnsi = transform_cypher_clause_as_subquery(child_parse_state,
transform_cypher_clause, c,
NULL, true);
- qry->targetList = makeTargetListFromRTE(p_child_parse_state, rte);
+ qry->targetList = makeTargetListFromPNSItem(p_child_parse_state, pnsi);
markTargetListOrigins(p_child_parse_state, qry->targetList);
@@ -2350,17 +2373,17 @@ static Node *transform_VLE_Function(cypher_parsestate *cpstate, Node *n,
/* function is like a plain relation */
RangeTblRef *rtr;
RangeTblEntry *rte;
+ ParseNamespaceItem *nsitem;
int rtindex;
- rte = transform_RangeFunction(cpstate, (RangeFunction *) n);
-
+ nsitem = transform_RangeFunction(cpstate, (RangeFunction *) n);
+ rte = nsitem->p_rte;
/* assume new rte is at end */
rtindex = list_length(pstate->p_rtable);
Assert(rte == rt_fetch(rtindex, pstate->p_rtable));
*top_rte = rte;
*top_rti = rtindex;
- *namespace = list_make1(create_namespace_item(rte, true, true, true,
- true));
+ *namespace = list_make1(nsitem);
rtr = makeNode(RangeTblRef);
rtr->rtindex = rtindex;
return (Node *) rtr;
@@ -2394,7 +2417,7 @@ static void setNamespaceLateralState(List *namespace, bool lateral_only,
* Code borrowed and inspired by PG's transformFromClauseItem. Static function
* to add in the VLE function as a FROM clause entry.
*/
-static RangeTblEntry *append_VLE_Func_to_FromClause(cypher_parsestate *cpstate,
+static ParseNamespaceItem *append_VLE_Func_to_FromClause(cypher_parsestate *cpstate,
Node *n)
{
ParseState *pstate = &cpstate->pstate;
@@ -2424,7 +2447,7 @@ static RangeTblEntry *append_VLE_Func_to_FromClause(cypher_parsestate *cpstate,
/* make all namespace items unconditionally visible */
setNamespaceLateralState(pstate->p_namespace, false, true);
- return rte;
+ return lfirst(list_head(namespace));
}
/*
@@ -2432,7 +2455,7 @@ static RangeTblEntry *append_VLE_Func_to_FromClause(cypher_parsestate *cpstate,
*
* --- transform a function call appearing in FROM
*/
-static RangeTblEntry *transform_RangeFunction(cypher_parsestate *cpstate,
+static ParseNamespaceItem *transform_RangeFunction(cypher_parsestate *cpstate,
RangeFunction *r)
{
ParseState *pstate = NULL;
@@ -2440,8 +2463,8 @@ static RangeTblEntry *transform_RangeFunction(cypher_parsestate *cpstate,
List *funcnames = NIL;
List *coldeflists = NIL;
bool is_lateral = false;
- RangeTblEntry *rte = NULL;
ListCell *lc = NULL;
+ ParseNamespaceItem *pnsi;
pstate = &cpstate->pstate;
@@ -2510,9 +2533,10 @@ static RangeTblEntry *transform_RangeFunction(cypher_parsestate *cpstate,
is_lateral = r->lateral || contain_vars_of_level((Node *) funcexprs, 0);
/* build an RTE for the function */
- rte = addRangeTableEntryForFunction(pstate, funcnames, funcexprs,
+ pnsi = addRangeTableEntryForFunction(pstate, funcnames, funcexprs,
coldeflists, r, is_lateral, true);
- return rte;
+
+ return pnsi;
}
static void transform_match_pattern(cypher_parsestate *cpstate, Query *query,
@@ -2634,7 +2658,7 @@ static FuncCall *prevent_duplicate_edges(cypher_parsestate *cpstate,
}
}
- return makeFuncCall(qualified_function_name, edges, -1);
+ return makeFuncCall(qualified_function_name, edges, COERCE_SQL_SYNTAX, -1);
}
/*
@@ -2750,7 +2774,7 @@ static List *make_join_condition_for_edge(cypher_parsestate *cpstate,
args = list_make3(left_id, right_id, entity->expr);
// add to quals
- quals = lappend(quals, makeFuncCall(qualified_func_name, args, -1));
+ quals = lappend(quals, makeFuncCall(qualified_func_name, args, COERCE_EXPLICIT_CALL, -1));
}
/*
@@ -2776,7 +2800,7 @@ static List *make_join_condition_for_edge(cypher_parsestate *cpstate,
args = list_make2(prev_edge->expr, entity->expr);
// create the function call
- fc = makeFuncCall(qualified_name, args, -1);
+ fc = makeFuncCall(qualified_name, args, COERCE_EXPLICIT_CALL, -1);
quals = lappend(quals, fc);
}
@@ -3011,7 +3035,7 @@ static List *join_to_entity(cypher_parsestate *cpstate,
args = list_make3(entity->expr, qual, make_bool_a_const(is_left_side));
// create the function call
- fc = makeFuncCall(qualified_name, args, -1);
+ fc = makeFuncCall(qualified_name, args, COERCE_EXPLICIT_CALL, -1);
quals = lappend(quals, fc);
@@ -3110,7 +3134,7 @@ static A_Expr *filter_vertices_on_label_id(cypher_parsestate *cpstate,
extract_label_id = makeString("_extract_label_id");
fc = makeFuncCall(list_make2(ag_catalog, extract_label_id),
- list_make1(id_field), -1);
+ list_make1(id_field), COERCE_EXPLICIT_CALL, -1);
return makeSimpleA_Expr(AEXPR_OP, "=", (Node *)fc, (Node *)n, -1);
}
@@ -3128,8 +3152,8 @@ static Node *create_property_constraints(cypher_parsestate *cpstate,
char *entity_name;
ColumnRef *cr;
Node *prop_expr, *const_expr;
- RangeTblEntry *rte;
Node *last_srf = pstate->p_last_srf;
+ ParseNamespaceItem *pnsi;
cr = makeNode(ColumnRef);
@@ -3138,10 +3162,9 @@ static Node *create_property_constraints(cypher_parsestate *cpstate,
cr->fields = list_make2(makeString(entity_name), makeString("properties"));
// use Postgres to get the properties' transform node
- if ((rte = find_rte(cpstate, entity_name)))
+ if ((pnsi = find_pnsi(cpstate, entity_name)))
{
- prop_expr = scanRTEForColumn(pstate, rte, AG_VERTEX_COLNAME_PROPERTIES,
- -1, 0, NULL);
+ prop_expr = scanNSItemForColumn(pstate, pnsi, 0, AG_VERTEX_COLNAME_PROPERTIES, -1);
}
else
{
@@ -3204,11 +3227,11 @@ static transform_entity *transform_VLE_edge_entity(cypher_parsestate *cpstate,
ParseState *pstate = NULL;
TargetEntry *te = NULL;
RangeFunction *rf = NULL;
- RangeTblEntry *rte = NULL;
FuncCall *func = NULL;
Alias *alias = NULL;
Node *var = NULL;
transform_entity *vle_entity = NULL;
+ ParseNamespaceItem *pnsi;
/* it better be a function call node */
Assert(IsA(rel->varlen, FuncCall));
@@ -3246,11 +3269,12 @@ static transform_entity *transform_VLE_edge_entity(cypher_parsestate *cpstate,
/*
* Add the RangeFunction to the FROM clause
*/
- rte = append_VLE_Func_to_FromClause(cpstate, (Node*)rf);
- Assert(rte != NULL);
+ pnsi = append_VLE_Func_to_FromClause(cpstate, (Node*)rf);
+ Assert(pnsi != NULL);
/* Get the var node for the VLE functions column name. */
- var = scanRTEForColumn(pstate, rte, "edges", -1, 0, NULL);
+ Assert(pnsi != NULL);
+ var = scanNSItemForColumn(pstate, pnsi, 0, "edges", -1);
Assert(var != NULL);
/*
@@ -3304,7 +3328,7 @@ static bool isa_special_VLE_case(cypher_path *path)
return false;
}
- cr = (cypher_relationship*)lfirst(lnext(list_head(path->path)));
+ cr = (cypher_relationship*)lfirst(lnext(path->path, list_head(path->path)));
if (cr->varlen != NULL)
{
@@ -3422,7 +3446,7 @@ static List *transform_match_entities(cypher_parsestate *cpstate, Query *query,
rel->dir == CYPHER_REL_DIR_NONE &&
!prev_entity->in_join_tree)
{
- cypher_node *node = (cypher_node *)lfirst(lnext(lc));
+ cypher_node *node = (cypher_node *)lfirst(lnext(path->path, lc));
if (!INCLUDE_NODE_IN_JOIN_TREE(path, node))
{
@@ -3526,19 +3550,19 @@ static List *make_path_join_quals(cypher_parsestate *cpstate, List *entities)
if (prev_node == NULL)
{
prev_node = lfirst(lc);
- lc = lnext(lc);
+ lc = lnext(entities, lc);
edge = lfirst(lc);
}
// Retrieve the next node and edge in the pattern.
- if (lnext(lc) != NULL)
+ if (lnext(entities, lc) != NULL)
{
- lc = lnext(lc);
+ lc = lnext(entities, lc);
next_node = lfirst(lc);
- if (lnext(lc) != NULL)
+ if (lnext(entities, lc) != NULL)
{
- lc = lnext(lc);
+ lc = lnext(entities, lc);
next_edge = lfirst(lc);
}
}
@@ -3687,7 +3711,7 @@ static Node *make_qual(cypher_parsestate *cpstate,
args = list_make1(entity->expr);
- node = (Node *)makeFuncCall(qualified_name, args, -1);
+ node = (Node *)makeFuncCall(qualified_name, args, COERCE_EXPLICIT_CALL, -1);
}
else
{
@@ -3729,10 +3753,10 @@ static Expr *transform_cypher_edge(cypher_parsestate *cpstate,
char *rel_name;
RangeVar *label_range_var;
Alias *alias;
- RangeTblEntry *rte;
int resno;
TargetEntry *te;
Expr *expr;
+ ParseNamespaceItem *pnsi;
if (!rel->label)
{
@@ -3839,17 +3863,19 @@ static Expr *transform_cypher_edge(cypher_parsestate *cpstate,
label_range_var = makeRangeVar(schema_name, rel_name, -1);
alias = makeAlias(rel->name, NIL);
- rte = addRangeTableEntry(pstate, label_range_var, alias,
+ pnsi = addRangeTableEntry(pstate, label_range_var, alias,
label_range_var->inh, true);
+ Assert(pnsi != NULL);
+
/*
* relation is visible (r.a in expression works) but attributes in the
* relation are not visible (a in expression doesn't work)
*/
- addRTEtoQuery(pstate, rte, true, true, false);
+ addNSItemToQuery(pstate, pnsi, true, true, false);
resno = pstate->p_next_resno++;
- expr = (Expr *)make_edge_expr(cpstate, rte, rel->label);
+ expr = (Expr *)make_edge_expr(cpstate, pnsi, rel->label);
if (rel->name)
{
@@ -3869,10 +3895,10 @@ static Expr *transform_cypher_node(cypher_parsestate *cpstate,
char *rel_name;
RangeVar *label_range_var;
Alias *alias;
- RangeTblEntry *rte;
int resno;
TargetEntry *te;
Expr *expr;
+ ParseNamespaceItem *pnsi;
if (!node->label)
{
@@ -3984,17 +4010,20 @@ static Expr *transform_cypher_node(cypher_parsestate *cpstate,
label_range_var = makeRangeVar(schema_name, rel_name, -1);
alias = makeAlias(node->name, NIL);
- rte = addRangeTableEntry(pstate, label_range_var, alias,
+ pnsi = addRangeTableEntry(pstate, label_range_var, alias,
label_range_var->inh, true);
+
+ Assert(pnsi != NULL);
+
/*
* relation is visible (r.a in expression works) but attributes in the
* relation are not visible (a in expression doesn't work)
*/
- addRTEtoQuery(pstate, rte, true, true, true);
+ addNSItemToQuery(pstate, pnsi, true, true, true);
resno = pstate->p_next_resno++;
- expr = (Expr *)make_vertex_expr(cpstate, rte, node->label);
+ expr = (Expr *)make_vertex_expr(cpstate, pnsi, node->label);
/* make target entry and add it */
te = makeTargetEntry(expr, resno, node->name, false);
@@ -4003,7 +4032,7 @@ static Expr *transform_cypher_node(cypher_parsestate *cpstate,
return expr;
}
-static Node *make_edge_expr(cypher_parsestate *cpstate, RangeTblEntry *rte,
+static Node *make_edge_expr(cypher_parsestate *cpstate, ParseNamespaceItem *pnsi,
char *label)
{
ParseState *pstate = (ParseState *)cpstate;
@@ -4019,13 +4048,11 @@ static Node *make_edge_expr(cypher_parsestate *cpstate, RangeTblEntry *rte,
func_oid = get_ag_func_oid("_agtype_build_edge", 5, GRAPHIDOID, GRAPHIDOID,
GRAPHIDOID, CSTRINGOID, AGTYPEOID);
- id = scanRTEForColumn(pstate, rte, AG_EDGE_COLNAME_ID, -1, 0, NULL);
+ id = scanNSItemForColumn(pstate, pnsi, 0, AG_EDGE_COLNAME_ID, -1);
- start_id = scanRTEForColumn(pstate, rte, AG_EDGE_COLNAME_START_ID, -1, 0,
- NULL);
+ start_id = scanNSItemForColumn(pstate, pnsi, 0, AG_EDGE_COLNAME_START_ID, -1);
- end_id = scanRTEForColumn(pstate, rte, AG_EDGE_COLNAME_END_ID, -1, 0,
- NULL);
+ end_id = scanNSItemForColumn(pstate, pnsi, 0, AG_EDGE_COLNAME_END_ID, -1);
label_name_func_oid = get_ag_func_oid("_label_name", 2, OIDOID,
GRAPHIDOID);
@@ -4041,8 +4068,7 @@ static Node *make_edge_expr(cypher_parsestate *cpstate, RangeTblEntry *rte,
InvalidOid, COERCE_EXPLICIT_CALL);
label_name_func_expr->location = -1;
- props = scanRTEForColumn(pstate, rte, AG_EDGE_COLNAME_PROPERTIES, -1, 0,
- NULL);
+ props = scanNSItemForColumn(pstate, pnsi, 0, AG_EDGE_COLNAME_PROPERTIES, -1);
args = list_make5(id, start_id, end_id, label_name_func_expr, props);
@@ -4052,7 +4078,7 @@ static Node *make_edge_expr(cypher_parsestate *cpstate, RangeTblEntry *rte,
return (Node *)func_expr;
}
-static Node *make_vertex_expr(cypher_parsestate *cpstate, RangeTblEntry *rte,
+static Node *make_vertex_expr(cypher_parsestate *cpstate, ParseNamespaceItem *pnsi,
char *label)
{
ParseState *pstate = (ParseState *)cpstate;
@@ -4065,10 +4091,12 @@ static Node *make_vertex_expr(cypher_parsestate *cpstate, RangeTblEntry *rte,
FuncExpr *func_expr;
FuncExpr *label_name_func_expr;
+ Assert(pnsi != NULL);
+
func_oid = get_ag_func_oid("_agtype_build_vertex", 3, GRAPHIDOID,
CSTRINGOID, AGTYPEOID);
- id = scanRTEForColumn(pstate, rte, AG_VERTEX_COLNAME_ID, -1, 0, NULL);
+ id = scanNSItemForColumn(pstate, pnsi, 0, AG_VERTEX_COLNAME_ID, -1);
label_name_func_oid = get_ag_func_oid("_label_name", 2, OIDOID,
GRAPHIDOID);
@@ -4084,8 +4112,7 @@ static Node *make_vertex_expr(cypher_parsestate *cpstate, RangeTblEntry *rte,
InvalidOid, COERCE_EXPLICIT_CALL);
label_name_func_expr->location = -1;
- props = scanRTEForColumn(pstate, rte, AG_VERTEX_COLNAME_PROPERTIES, -1, 0,
- NULL);
+ props = scanNSItemForColumn(pstate, pnsi, 0, AG_VERTEX_COLNAME_PROPERTIES, -1);
args = list_make3(id, label_name_func_expr, props);
@@ -4274,6 +4301,7 @@ transform_create_cypher_edge(cypher_parsestate *cpstate, List **target_list,
TargetEntry *te;
char *alias;
AttrNumber resno;
+ ParseNamespaceItem *pnsi;
if (edge->label)
{
@@ -4360,8 +4388,9 @@ transform_create_cypher_edge(cypher_parsestate *cpstate, List **target_list,
// Store the relid
rel->relid = RelationGetRelid(label_relation);
- rte = addRangeTableEntryForRelation((ParseState *)cpstate, label_relation,
+ pnsi = addRangeTableEntryForRelation((ParseState *)cpstate, label_relation,
AccessShareLock, NULL, false, false);
+ rte = pnsi->p_rte;
rte->requiredPerms = ACL_INSERT;
// Build Id expression, always use the default logic
@@ -4381,7 +4410,7 @@ transform_create_cypher_edge(cypher_parsestate *cpstate, List **target_list,
*target_list = lappend(*target_list, te);
// Keep the lock
- heap_close(label_relation, NoLock);
+ table_close(label_relation, NoLock);
return rel;
}
@@ -4390,17 +4419,17 @@ static bool variable_exists(cypher_parsestate *cpstate, char *name)
{
ParseState *pstate = (ParseState *)cpstate;
Node *id;
- RangeTblEntry *rte;
if (name == NULL)
{
return false;
}
- rte = find_rte(cpstate, PREV_CYPHER_CLAUSE_ALIAS);
- if (rte)
+ ParseNamespaceItem *pnsi;
+ pnsi = find_pnsi(cpstate, PREV_CYPHER_CLAUSE_ALIAS);
+ if (pnsi)
{
- id = scanRTEForColumn(pstate, rte, name, -1, 0, NULL);
+ id = scanNSItemForColumn(pstate, pnsi, 0, name, -1);
return id != NULL;
}
@@ -4543,6 +4572,7 @@ transform_create_cypher_new_node(cypher_parsestate *cpstate,
Expr *props;
char *alias;
int resno;
+ ParseNamespaceItem *pnsi;
rel->type = LABEL_KIND_VERTEX;
rel->tuple_position = InvalidAttrNumber;
@@ -4586,8 +4616,9 @@ transform_create_cypher_new_node(cypher_parsestate *cpstate,
// Store the relid
rel->relid = RelationGetRelid(label_relation);
- rte = addRangeTableEntryForRelation((ParseState *)cpstate, label_relation,
+ pnsi = addRangeTableEntryForRelation((ParseState *)cpstate, label_relation,
AccessShareLock, NULL, false, false);
+ rte = pnsi->p_rte;
rte->requiredPerms = ACL_INSERT;
// id
@@ -4605,7 +4636,7 @@ transform_create_cypher_new_node(cypher_parsestate *cpstate,
te = makeTargetEntry(props, resno, alias, false);
*target_list = lappend(*target_list, te);
- heap_close(label_relation, NoLock);
+ table_close(label_relation, NoLock);
if (node->name)
{
@@ -4695,7 +4726,7 @@ static Expr *cypher_create_properties(cypher_parsestate *cpstate,
* This function is similar to transformFromClause() that is called with a
* single RangeSubselect.
*/
-static RangeTblEntry *
+static ParseNamespaceItem *
transform_cypher_clause_as_subquery(cypher_parsestate *cpstate,
transform_method transform,
cypher_clause *clause,
@@ -4707,6 +4738,7 @@ transform_cypher_clause_as_subquery(cypher_parsestate *cpstate,
RangeTblEntry *rte;
ParseExprKind old_expr_kind = pstate->p_expr_kind;
bool lateral = pstate->p_lateral_active;
+ ParseNamespaceItem *pnsi;
/*
* We allow expression kinds of none, where, and subselect. Others MAY need
@@ -4746,7 +4778,8 @@ transform_cypher_clause_as_subquery(cypher_parsestate *cpstate,
alias = makeAlias(PREV_CYPHER_CLAUSE_ALIAS, NIL);
}
- rte = addRangeTableEntryForSubquery(pstate, query, alias, lateral, true);
+ pnsi = addRangeTableEntryForSubquery(pstate, query, alias, lateral, true);
+ rte = pnsi->p_rte;
/*
* NOTE: skip namespace conflicts check if the rte will be the only
@@ -4768,7 +4801,7 @@ transform_cypher_clause_as_subquery(cypher_parsestate *cpstate,
errmsg("rte must be last entry in p_rtable")));
}
- namespace = list_make1(create_namespace_item(rte, true, true, false, true));
+ namespace = list_make1(pnsi);
checkNameSpaceConflicts(pstate, pstate->p_namespace, namespace);
}
@@ -4776,10 +4809,10 @@ transform_cypher_clause_as_subquery(cypher_parsestate *cpstate,
if (add_rte_to_query)
{
// all variables(attributes) from the previous clause(subquery) are visible
- addRTEtoQuery(pstate, rte, true, false, true);
+ addNSItemToQuery(pstate, pnsi, true, false, true);
}
- return rte;
+ return pnsi;
}
/*
@@ -5076,12 +5109,11 @@ transform_merge_make_lateral_join(cypher_parsestate *cpstate, Query *query,
int i;
Alias *l_alias;
Alias *r_alias;
- RangeTblEntry *rte;
RangeTblEntry *l_rte, *r_rte;
ParseNamespaceItem *l_nsitem, *r_nsitem;
JoinExpr *j = makeNode(JoinExpr);
List *res_colnames = NIL, *res_colvars = NIL;
- ParseNamespaceItem *nsitem;
+ ParseNamespaceItem *jnsitem;
ParseExprKind tmp;
cypher_merge *self = (cypher_merge *)clause->self;
cypher_path *path;
@@ -5133,13 +5165,22 @@ transform_merge_make_lateral_join(cypher_parsestate *cpstate, Query *query,
* Resolve the column names and variables between the two subqueries,
* in most cases, we can expect there to be overlap
*/
- get_res_cols(pstate, l_rte, r_rte, &res_colnames, &res_colvars);
+ get_res_cols(pstate, l_nsitem, r_nsitem, &res_colnames, &res_colvars);
// make the RTE for the join
- rte = addRangeTableEntryForJoin(pstate, res_colnames, j->jointype,
- res_colvars, j->alias, true);
-
- j->rtindex = RTERangeTablePosn(pstate, rte, NULL);
+ jnsitem = addRangeTableEntryForJoin(pstate,
+ res_colnames,
+ NULL,
+ j->jointype,
+ 0,
+ res_colvars,
+ NIL,
+ NIL,
+ j->alias,
+ NULL,
+ true);
+
+ j->rtindex = jnsitem->p_rtindex;
/*
* The index of a node in the p_joinexpr list is expected to match the
@@ -5159,19 +5200,14 @@ transform_merge_make_lateral_join(cypher_parsestate *cpstate, Query *query,
pstate->p_expr_kind = tmp;
- /*
- * Create the namespace item for the joined subqueries, and append
- * to the ParseState's list of namespaces.
- */
- nsitem = create_namespace_item(rte, true, true, false, true);
-
- pstate->p_namespace = lappend(pstate->p_namespace, nsitem);
+ /* add jnsitem to column namespace only */
+ addNSItemToQuery(pstate, jnsitem, false, true, true);
/*
* Create the targetList from the joined subqueries, add everything.
*/
query->targetList = list_concat(query->targetList,
- make_target_list_from_join(pstate, rte));
+ make_target_list_from_join(pstate, jnsitem->p_rte));
/*
* For the metadata need to create paths, find the tuple position that
@@ -5305,6 +5341,7 @@ transform_merge_cypher_edge(cypher_parsestate *cpstate, List **target_list,
Relation label_relation;
RangeVar *rv;
RangeTblEntry *rte;
+ ParseNamespaceItem *pnsi;
if (edge->name != NULL)
{
@@ -5374,8 +5411,9 @@ transform_merge_cypher_edge(cypher_parsestate *cpstate, List **target_list,
// Store the relid
rel->relid = RelationGetRelid(label_relation);
- rte = addRangeTableEntryForRelation((ParseState *)cpstate, label_relation,
+ pnsi = addRangeTableEntryForRelation((ParseState *)cpstate, label_relation,
AccessShareLock, NULL, false, false);
+ rte = pnsi->p_rte;
rte->requiredPerms = ACL_INSERT;
// Build Id expression, always use the default logic
@@ -5386,7 +5424,7 @@ transform_merge_cypher_edge(cypher_parsestate *cpstate, List **target_list,
edge->props, ENT_EDGE);
// Keep the lock
- heap_close(label_relation, NoLock);
+ table_close(label_relation, NoLock);
return rel;
}
@@ -5403,6 +5441,7 @@ transform_merge_cypher_node(cypher_parsestate *cpstate, List **target_list,
Relation label_relation;
RangeVar *rv;
RangeTblEntry *rte;
+ ParseNamespaceItem *pnsi;
if (node->name != NULL)
{
@@ -5479,8 +5518,9 @@ transform_merge_cypher_node(cypher_parsestate *cpstate, List **target_list,
// Store the relid
rel->relid = RelationGetRelid(label_relation);
- rte = addRangeTableEntryForRelation((ParseState *)cpstate, label_relation,
+ pnsi = addRangeTableEntryForRelation((ParseState *)cpstate, label_relation,
AccessShareLock, NULL, false, false);
+ rte = pnsi->p_rte;
rte->requiredPerms = ACL_INSERT;
// id
@@ -5490,7 +5530,7 @@ transform_merge_cypher_node(cypher_parsestate *cpstate, List **target_list,
rel->prop_expr = cypher_create_properties(cpstate, rel, label_relation,
node->props, ENT_VERTEX);
- heap_close(label_relation, NoLock);
+ table_close(label_relation, NoLock);
return rel;
}
@@ -5520,27 +5560,22 @@ static cypher_clause *convert_merge_to_match(cypher_merge *merge)
}
/*
- * Creates a namespace item for the given rte. boolean arguements will
- * let the rest of the ParseState know if the relation and/or columns are
- * visible, whether the rte is only usable in lateral joins, and if the rte
- * is accessible in lateral joins.
+ * Get a namespace item for the given rte.
*/
-static ParseNamespaceItem *create_namespace_item(RangeTblEntry *rte,
- bool p_rel_visible,
- bool p_cols_visible,
- bool p_lateral_only,
- bool p_lateral_ok)
+static ParseNamespaceItem *get_namespace_item(ParseState *pstate,
+ RangeTblEntry *rte)
{
- ParseNamespaceItem *nsitem;
-
- nsitem = palloc(sizeof(*nsitem));
- nsitem->p_rte = rte;
- nsitem->p_rel_visible = p_rel_visible;
- nsitem->p_cols_visible = p_cols_visible;
- nsitem->p_lateral_only = p_lateral_only;
- nsitem->p_lateral_ok = p_lateral_ok;
-
- return nsitem;
+ ParseNamespaceItem *nsitem = NULL;
+ ListCell *l;
+
+ foreach(l, pstate->p_namespace)
+ {
+ nsitem = lfirst(l);
+ if (rte == nsitem->p_rte )
+ return nsitem;
+ }
+ Assert(nsitem != NULL);
+ return NULL;
}
/*
@@ -5588,10 +5623,12 @@ static void handle_prev_clause(cypher_parsestate *cpstate, Query *query,
cypher_clause *clause, bool first_rte)
{
ParseState *pstate = (ParseState *) cpstate;
- RangeTblEntry *rte;
+
int rtindex;
+ ParseNamespaceItem *pnsi;
+
+ pnsi = transform_prev_cypher_clause(cpstate, clause, true);
- rte = transform_prev_cypher_clause(cpstate, clause, true);
rtindex = list_length(pstate->p_rtable);
// rte is the first RangeTblEntry in pstate
@@ -5601,5 +5638,24 @@ static void handle_prev_clause(cypher_parsestate *cpstate, Query *query,
}
// add all the rte's attributes to the current queries targetlist
- query->targetList = expandRelAttrs(pstate, rte, rtindex, 0, -1);
+ query->targetList = expandNSItemAttrs(pstate, pnsi, 0, -1);
}
+
+ParseNamespaceItem *find_pnsi(cypher_parsestate *cpstate, char *varname)
+{
+ ParseState *pstate = (ParseState *) cpstate;
+ ListCell *lc;
+
+ foreach (lc, pstate->p_namespace)
+ {
+ ParseNamespaceItem *pnsi = (ParseNamespaceItem *)lfirst(lc);
+ Alias *alias = pnsi->p_rte->alias;
+ if (!alias)
+ continue;
+
+ if (!strcmp(alias->aliasname, varname))
+ return pnsi;
+ }
+
+ return NULL;
+}
\ No newline at end of file
diff --git a/src/backend/parser/cypher_expr.c b/src/backend/parser/cypher_expr.c
index f0627eb..688ff8d 100644
--- a/src/backend/parser/cypher_expr.c
+++ b/src/backend/parser/cypher_expr.c
@@ -49,6 +49,7 @@
#include "commands/label_commands.h"
#include "nodes/cypher_nodes.h"
#include "parser/cypher_expr.h"
+#include "parser/cypher_item.h"
#include "parser/cypher_parse_node.h"
#include "parser/cypher_transform_entity.h"
#include "utils/ag_func.h"
@@ -92,7 +93,7 @@ static Node *transform_CoalesceExpr(cypher_parsestate *cpstate,
CoalesceExpr *cexpr);
static Node *transform_SubLink(cypher_parsestate *cpstate, SubLink *sublink);
static Node *transform_FuncCall(cypher_parsestate *cpstate, FuncCall *fn);
-static Node *transform_WholeRowRef(ParseState *pstate, RangeTblEntry *rte,
+static Node *transform_WholeRowRef(ParseState *pstate, ParseNamespaceItem *pnsi,
int location);
static ArrayExpr *make_agtype_array_expr(List *args);
@@ -256,15 +257,18 @@ static Node *transform_A_Const(cypher_parsestate *cpstate, A_Const *ac)
* Private function borrowed from PG's transformWholeRowRef.
* Construct a whole-row reference to represent the notation "relation.*".
*/
-static Node *transform_WholeRowRef(ParseState *pstate, RangeTblEntry *rte,
+static Node *transform_WholeRowRef(ParseState *pstate, ParseNamespaceItem *pnsi,
int location)
{
Var *result;
int vnum;
- int sublevels_up;
+ RangeTblEntry *rte;
+
+ Assert(pnsi->p_rte != NULL);
+ rte = pnsi->p_rte;
/* Find the RTE's rangetable location */
- vnum = RTERangeTablePosn(pstate, rte, &sublevels_up);
+ vnum = pnsi->p_rtindex;
/*
* Build the appropriate referencing node. Note that if the RTE is a
@@ -274,13 +278,13 @@ static Node *transform_WholeRowRef(ParseState *pstate, RangeTblEntry *rte,
* historically. One argument for it is that "rel" and "rel.*" mean the
* same thing for composite relations, so why not for scalar functions...
*/
- result = makeWholeRowVar(rte, vnum, sublevels_up, true);
+ result = makeWholeRowVar(rte, vnum, 0, true); // TODO: Review sublevels_up impact.
/* location is not filled in by makeWholeRowVar */
result->location = location;
/* mark relation as requiring whole-row SELECT access */
- markVarForSelectPriv(pstate, result, rte);
+ markVarForSelectPriv(pstate, result);
return (Node *)result;
}
@@ -292,7 +296,6 @@ static Node *transform_WholeRowRef(ParseState *pstate, RangeTblEntry *rte,
static Node *transform_ColumnRef(cypher_parsestate *cpstate, ColumnRef *cref)
{
ParseState *pstate = (ParseState *)cpstate;
- RangeTblEntry *rte = NULL;
Node *field1 = NULL;
Node *field2 = NULL;
char *colname = NULL;
@@ -300,6 +303,7 @@ static Node *transform_ColumnRef(cypher_parsestate *cpstate, ColumnRef *cref)
char *relname = NULL;
Node *node = NULL;
int levels_up;
+ ParseNamespaceItem *pnsi;
switch (list_length(cref->fields))
{
@@ -339,11 +343,11 @@ static Node *transform_ColumnRef(cypher_parsestate *cpstate, ColumnRef *cref)
* PostQUEL-inspired syntax. The preferred form now is
* "rel.*".
*/
- rte = refnameRangeTblEntry(pstate, NULL, colname,
+ pnsi = refnameNamespaceItem(pstate, NULL, colname,
cref->location, &levels_up);
- if (rte)
+ if (pnsi)
{
- node = transform_WholeRowRef(pstate, rte, cref->location);
+ node = transform_WholeRowRef(pstate, pnsi, cref->location);
}
else
{
@@ -379,9 +383,10 @@ static Node *transform_ColumnRef(cypher_parsestate *cpstate, ColumnRef *cref)
}
/* locate the referenced RTE */
- rte = refnameRangeTblEntry(pstate, nspname, relname,
+ pnsi = refnameNamespaceItem(pstate, nspname, relname,
cref->location, &levels_up);
- if (rte == NULL)
+
+ if (pnsi == NULL)
{
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
@@ -397,15 +402,15 @@ static Node *transform_ColumnRef(cypher_parsestate *cpstate, ColumnRef *cref)
*/
if (IsA(field2, A_Star))
{
- node = transform_WholeRowRef(pstate, rte, cref->location);
+ node = transform_WholeRowRef(pstate, pnsi, cref->location);
break;
}
Assert(IsA(field2, String));
/* try to identify as a column of the RTE */
- node = scanRTEForColumn(pstate, rte, colname, cref->location, 0,
- NULL);
+ node = scanNSItemForColumn(pstate, pnsi, 0, colname, cref->location);
+
if (node == NULL)
{
ereport(ERROR,
@@ -614,9 +619,9 @@ static Node *transform_cypher_map(cypher_parsestate *cpstate, cypher_map *cm)
Const *newkey;
key = lfirst(le);
- le = lnext(le);
+ le = lnext(cm->keyvals, le);
val = lfirst(le);
- le = lnext(le);
+ le = lnext(cm->keyvals, le);
newval = transform_cypher_expr_recurse(cpstate, val);
@@ -956,7 +961,7 @@ static Node *transform_cypher_typecast(cypher_parsestate *cpstate,
}
/* make a function call node */
- fnode = makeFuncCall(fname, list_make1(ctypecast->expr),
+ fnode = makeFuncCall(fname, list_make1(ctypecast->expr), COERCE_SQL_SYNTAX,
ctypecast->location);
/* return the transformed function */
@@ -1302,4 +1307,4 @@ static Node *transform_SubLink(cypher_parsestate *cpstate, SubLink *sublink)
elog(ERROR, "unsupported SubLink type");
return result;
-}
+}
\ No newline at end of file
diff --git a/src/backend/parser/cypher_gram.y b/src/backend/parser/cypher_gram.y
index b751cdb..b3563d1 100644
--- a/src/backend/parser/cypher_gram.y
+++ b/src/backend/parser/cypher_gram.y
@@ -2051,11 +2051,11 @@ static Node *make_function_expr(List *func_name, List *exprs, int location)
funcname = func_name;
/* build the function call */
- fnode = makeFuncCall(funcname, exprs, location);
+ fnode = makeFuncCall(funcname, exprs, COERCE_SQL_SYNTAX, location);
}
/* all other functions are passed as is */
else
- fnode = makeFuncCall(func_name, exprs, location);
+ fnode = makeFuncCall(func_name, exprs, COERCE_SQL_SYNTAX, location);
/* return the node */
return (Node *)fnode;
diff --git a/src/backend/parser/cypher_item.c b/src/backend/parser/cypher_item.c
index c90073b..10469b9 100644
--- a/src/backend/parser/cypher_item.c
+++ b/src/backend/parser/cypher_item.c
@@ -152,7 +152,6 @@ static List *ExpandAllTables(ParseState *pstate, int location)
foreach(l, pstate->p_namespace)
{
ParseNamespaceItem *nsitem = (ParseNamespaceItem *) lfirst(l);
- RangeTblEntry *rte = nsitem->p_rte;
/* Ignore table-only items */
if (!nsitem->p_cols_visible)
@@ -162,10 +161,8 @@ static List *ExpandAllTables(ParseState *pstate, int location)
/* Remember we found a p_cols_visible item */
found_table = true;
- target = list_concat(target, expand_rel_attrs(pstate, rte,
- RTERangeTablePosn(pstate,
- rte,
- NULL),
+ target = list_concat(target, expand_rel_attrs(pstate, nsitem->p_rte,
+ nsitem->p_rtindex,
0, location));
}
@@ -221,10 +218,10 @@ static List *expand_rel_attrs(ParseState *pstate, RangeTblEntry *rte,
te_list = lappend(te_list, te);
/* Require read access to each column */
- markVarForSelectPriv(pstate, varnode, rte);
+ markVarForSelectPriv(pstate, varnode);
}
Assert(name == NULL && var == NULL); /* lists not the same length? */
return te_list;
-}
+}
\ No newline at end of file
diff --git a/src/backend/parser/cypher_parse_agg.c b/src/backend/parser/cypher_parse_agg.c
index 8fdb71d..e690336 100644
--- a/src/backend/parser/cypher_parse_agg.c
+++ b/src/backend/parser/cypher_parse_agg.c
@@ -125,7 +125,7 @@ void parse_check_aggregates(ParseState *pstate, Query *qry)
if (gset_common)
{
- for_each_cell(l, lnext(list_head(gsets)))
+ for_each_cell(l, gsets, lnext(gsets, list_head(gsets)))
{
gset_common = list_intersection_int(gset_common, lfirst(l));
if (!gset_common)
@@ -807,7 +807,7 @@ static List * expand_grouping_sets(List *groupingSets, int limit)
result = lappend(result, list_union_int(NIL, (List *) lfirst(lc)));
}
- for_each_cell(lc, lnext(list_head(expanded_groups)))
+ for_each_cell(lc, expanded_groups, lnext(expanded_groups, list_head(expanded_groups)))
{
List *p = lfirst(lc);
List *new_result = NIL;
diff --git a/src/backend/parser/cypher_parse_node.c b/src/backend/parser/cypher_parse_node.c
index 269dd3c..d26b3ec 100644
--- a/src/backend/parser/cypher_parse_node.c
+++ b/src/backend/parser/cypher_parse_node.c
@@ -106,25 +106,6 @@ static void errpos_ecb(void *arg)
errposition(query_pos + geterrposition());
}
-RangeTblEntry *find_rte(cypher_parsestate *cpstate, char *varname)
-{
- ParseState *pstate = (ParseState *) cpstate;
- ListCell *lc;
-
- foreach (lc, pstate->p_rtable)
- {
- RangeTblEntry *rte = (RangeTblEntry *)lfirst(lc);
- Alias *alias = rte->alias;
- if (!alias)
- continue;
-
- if (!strcmp(alias->aliasname, varname))
- return rte;
- }
-
- return NULL;
-}
-
/*
* Generates a default alias name for when a query needs on and the parse
* state does not provide one.
diff --git a/src/backend/utils/adt/age_global_graph.c b/src/backend/utils/adt/age_global_graph.c
index b980bd6..f2e726a 100644
--- a/src/backend/utils/adt/age_global_graph.c
+++ b/src/backend/utils/adt/age_global_graph.c
@@ -31,6 +31,7 @@
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "commands/label_commands.h"
+#include "common/hashfn.h"
#include "catalog/ag_graph.h"
#include "catalog/ag_label.h"
diff --git a/src/backend/utils/adt/age_vle.c b/src/backend/utils/adt/age_vle.c
index e3e6385..8596772 100644
--- a/src/backend/utils/adt/age_vle.c
+++ b/src/backend/utils/adt/age_vle.c
@@ -22,6 +22,7 @@
#include "access/heapam.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
+#include "common/hashfn.h"
#include "funcapi.h"
#include "utils/lsyscache.h"
diff --git a/src/backend/utils/adt/agtype_gin.c b/src/backend/utils/adt/agtype_gin.c
index 9a9adc9..7dcc213 100644
--- a/src/backend/utils/adt/agtype_gin.c
+++ b/src/backend/utils/adt/agtype_gin.c
@@ -48,8 +48,6 @@ typedef struct PathHashStack
static Datum make_text_key(char flag, const char *str, int len);
static Datum make_scalar_key(const agtype_value *scalar_val, bool is_key);
-#define MAXINT8LEN 25
-
/*
*
* agtype_ops GIN opclass support functions
diff --git a/src/backend/utils/cache/ag_cache.c b/src/backend/utils/cache/ag_cache.c
index 09a5f51..1a0f5b4 100644
--- a/src/backend/utils/cache/ag_cache.c
+++ b/src/backend/utils/cache/ag_cache.c
@@ -442,6 +442,7 @@ static void fill_graph_cache_data(graph_cache_data *cache_data,
{
bool is_null;
Datum value;
+ Name name;
// ag_graph.id
value = heap_getattr(tuple, Anum_ag_graph_oid, tuple_desc, &is_null);
@@ -450,7 +451,9 @@ static void fill_graph_cache_data(graph_cache_data *cache_data,
// ag_graph.name
value = heap_getattr(tuple, Anum_ag_graph_name, tuple_desc, &is_null);
Assert(!is_null);
- namecpy(&cache_data->name, DatumGetName(value));
+ name = DatumGetName(value);
+ Assert(name != NULL);
+ namestrcpy(&cache_data->name, name->data);
// ag_graph.namespace
value = heap_getattr(tuple, Anum_ag_graph_namespace, tuple_desc, &is_null);
Assert(!is_null);
@@ -787,7 +790,7 @@ static void *label_name_graph_cache_hash_search(Name name, Oid graph,
label_name_graph_cache_key key;
// initialize the hash key for label_name_graph_cache_hash
- namecpy(&key.name, name);
+ namestrcpy(&key.name, name->data);
key.graph = graph;
return hash_search(label_name_graph_cache_hash, &key, action, found);
@@ -934,11 +937,14 @@ static void fill_label_cache_data(label_cache_data *cache_data,
{
bool is_null;
Datum value;
+ Name name;
// ag_label.name
value = heap_getattr(tuple, Anum_ag_label_name, tuple_desc, &is_null);
Assert(!is_null);
- namecpy(&cache_data->name, DatumGetName(value));
+ name = DatumGetName(value);
+ Assert(name != NULL);
+ namestrcpy(&cache_data->name, name->data);
// ag_label.graph
value = heap_getattr(tuple, Anum_ag_label_graph, tuple_desc, &is_null);
Assert(!is_null);
diff --git a/src/include/parser/cypher_parse_node.h b/src/include/parser/cypher_parse_node.h
index 268eb1a..e08b79b 100644
--- a/src/include/parser/cypher_parse_node.h
+++ b/src/include/parser/cypher_parse_node.h
@@ -62,7 +62,6 @@ void free_cypher_parsestate(cypher_parsestate *cpstate);
void setup_errpos_ecb(errpos_ecb_state *ecb_state, ParseState *pstate,
int query_loc);
void cancel_errpos_ecb(errpos_ecb_state *ecb_state);
-RangeTblEntry *find_rte(cypher_parsestate *cpstate, char *varname);
char *get_next_default_alias(cypher_parsestate *cpstate);
#endif