This is an automated email from the ASF dual-hosted git repository.

jgemignani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/age.git


The following commit(s) were added to refs/heads/master by this push:
     new f4858466 Merge PG13 (version 1.3.0) into the master branch (#1022)
f4858466 is described below

commit f4858466ce572553c0c9820e243504d2c93fdb13
Author: John Gemignani <[email protected]>
AuthorDate: Wed Jul 12 14:18:34 2023 -0700

    Merge PG13 (version 1.3.0) into the master branch (#1022)
    
    Merged branch PG13 (version 1.3.0) into the master branch.
    
    PR 1022 contains the merge of the branch PG13 (version 1.3.0) into
    the master branch. This will fold in all of the changes that are
    specific to the branch PG13 from the branch PG12, of which it originated.
    As the master branch is already ahead of version 1.3.0, it will create a
    master branch that is on PostgreSQL version 13 and completely up-to-date.
    
        Note: Effective as of the merge of this PR, the master branch will be on
        PostgreSQL version 13.
    
    On branch master_PostgreSQL13 the following files were modified to
    correct conflicts, whitespace, typos, duplicates, and to add clarity -
    
            .github/workflows/go-driver.yml
            .github/workflows/jdbc-driver.yaml
            .github/workflows/nodejs-driver.yaml
            .github/workflows/python-driver.yaml
            .github/workflows/installcheck.yaml
            .gitignore
            Dockerfile
            README.md
            RELEASE
            age--1.3.0.sql
            drivers/README
            drivers/docker-compose.yml
            drivers/golang/README.md
            drivers/golang/age/builder.go
            drivers/golang/age/mapper.go
            drivers/golang/go.mod
            drivers/golang/go.sum
            drivers/golang/parser/README.md
            drivers/jdbc/README.md
            drivers/jdbc/lib/build.gradle.kts
            
drivers/jdbc/lib/src/test/java/org/apache/age/jdbc/BaseDockerizedTest.java
            drivers/nodejs/README.md
            drivers/python/README.md
            drivers/python/age/age.py
            drivers/python/age/exceptions.py
            drivers/python/setup.py
            drivers/python/test_age_py.py
            regress/expected/age_global_graph.out
            regress/expected/catalog.out
            regress/expected/cypher_call.out
            regress/expected/cypher_match.out
            regress/expected/cypher_merge.out
            regress/expected/cypher_set.out
            regress/sql/age_global_graph.sql
            regress/sql/catalog.sql
            regress/sql/cypher_call.sql
            regress/sql/cypher_match.sql
            regress/sql/cypher_set.sql
            src/backend/commands/label_commands.c
            src/backend/executor/cypher_create.c
            src/backend/executor/cypher_merge.c
            src/backend/executor/cypher_set.c
            src/backend/executor/cypher_utils.c
            src/backend/nodes/cypher_readfuncs.c
            src/backend/parser/cypher_analyze.c
            src/backend/parser/cypher_clause.c
            src/backend/parser/cypher_gram.y
            src/backend/utils/adt/agtype.c
            src/backend/utils/adt/graphid.c
            src/backend/utils/cache/ag_cache.c
            src/backend/utils/graph_generation.c
            src/backend/utils/load/ag_load_edges.c
            src/backend/utils/load/ag_load_labels.c
            src/include/nodes/cypher_nodes.h
---
 .github/workflows/go-driver.yml          |  12 +-
 .github/workflows/installcheck.yaml      |  30 +-
 .github/workflows/jdbc-driver.yaml       |  12 +-
 .github/workflows/nodejs-driver.yaml     |  12 +-
 .github/workflows/python-driver.yaml     |  12 +-
 Dockerfile                               |   4 +-
 Makefile                                 |   2 +
 README.md                                |   4 +-
 RELEASE                                  |   9 +-
 age--1.3.0.sql                           |  33 +--
 drivers/golang/age/builder.go            |   1 -
 drivers/golang/age/mapper.go             |   1 -
 regress/sql/cypher_call.sql              |   1 -
 src/backend/catalog/ag_catalog.c         |   8 +-
 src/backend/commands/label_commands.c    |   7 +-
 src/backend/executor/cypher_create.c     |  19 +-
 src/backend/executor/cypher_merge.c      |  18 +-
 src/backend/executor/cypher_set.c        |   1 +
 src/backend/parser/ag_scanner.l          |  11 -
 src/backend/parser/cypher_analyze.c      |  23 +-
 src/backend/parser/cypher_clause.c       | 459 ++++++++++++++++++-------------
 src/backend/parser/cypher_expr.c         |  46 ++--
 src/backend/parser/cypher_item.c         |   8 +-
 src/backend/parser/cypher_parse_agg.c    |   5 +-
 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.c           |   8 +-
 src/backend/utils/adt/agtype_gin.c       |   1 -
 src/backend/utils/cache/ag_cache.c       |  18 +-
 src/backend/utils/graph_generation.c     |   1 -
 src/backend/utils/load/ag_load_edges.c   |   1 -
 src/include/parser/cypher_parse_node.h   |   1 -
 33 files changed, 425 insertions(+), 364 deletions(-)

diff --git a/.github/workflows/go-driver.yml b/.github/workflows/go-driver.yml
index afba9cbe..830b1e7a 100644
--- a/.github/workflows/go-driver.yml
+++ b/.github/workflows/go-driver.yml
@@ -2,10 +2,10 @@ name: Go Driver Tests
 
 on:
   push:
-    branches: [ "master", "PG12" ]
+    branches: [ "master", "PG13" ]
 
   pull_request:
-    branches: [ "master", "PG12" ]
+    branches: [ "master", "PG13" ]
 
 jobs:
   build:
@@ -26,14 +26,14 @@ jobs:
         if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
           if [[ "$GITHUB_REF" == "refs/heads/master" ]]; then
             echo "TAG=latest" >> $GITHUB_ENV
-          elif [[ "$GITHUB_REF" == "refs/heads/PG12" ]]; then
-            echo "TAG=PG12_latest" >> $GITHUB_ENV
+          elif [[ "$GITHUB_REF" == "refs/heads/PG13" ]]; then
+            echo "TAG=PG13_latest" >> $GITHUB_ENV
           fi
         elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
           if [[ "$GITHUB_BASE_REF" == "master" ]]; then
             echo "TAG=latest" >> $GITHUB_ENV
-          elif [[ "$GITHUB_BASE_REF" == "PG12" ]]; then
-            echo "TAG=PG12_latest" >> $GITHUB_ENV
+          elif [[ "$GITHUB_BASE_REF" == "PG13" ]]; then
+            echo "TAG=PG13_latest" >> $GITHUB_ENV
           fi
         fi
 
diff --git a/.github/workflows/installcheck.yaml 
b/.github/workflows/installcheck.yaml
index c35979cd..607731cb 100644
--- a/.github/workflows/installcheck.yaml
+++ b/.github/workflows/installcheck.yaml
@@ -2,32 +2,32 @@ name: Build / Regression
 
 on:
   push:
-    branches: [ 'master', 'PG12' ]
+    branches: [ 'master', 'PG13' ]
   pull_request:
-    branches: [ 'master', 'PG12' ]
+    branches: [ 'master', 'PG13' ]
 
 jobs:
   build:
     runs-on: ubuntu-latest
 
     steps:
-      - name: Get latest commit id of PostgreSQL 12
+      - name: Get latest commit id of PostgreSQL 13
         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_13_STABLE | awk 
'{print $1}')" >> $GITHUB_ENV
 
-      - name: Cache PostgreSQL 12
+      - name: Cache PostgreSQL 13
         uses: actions/cache@v3
-        id: pg12cache
+        id: pg13cache
         with:
-          path: ~/pg12
-          key: ${{ runner.os }}-v1-pg12-${{ env.PG_COMMIT_HASH }}
+          path: ~/pg13
+          key: ${{ runner.os }}-v1-pg13-${{ env.PG_COMMIT_HASH }}
 
-      - name: Install PostgreSQL 12
-        if: steps.pg12cache.outputs.cache-hit != 'true'
+      - name: Install PostgreSQL 13
+        if: steps.pg13cache.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_13_STABLE 
git://git.postgresql.org/git/postgresql.git ~/pg13source
+          cd ~/pg13source
+          ./configure --prefix=$HOME/pg13 CFLAGS="-std=gnu99 -ggdb -O0" 
--enable-cassert
           make install -j$(nproc) > /dev/null
 
       - uses: actions/checkout@v3
@@ -35,12 +35,12 @@ jobs:
       - name: Build
         id: build
         run: |
-          make PG_CONFIG=$HOME/pg12/bin/pg_config install -j$(nproc)
+          make PG_CONFIG=$HOME/pg13/bin/pg_config install -j$(nproc)
 
       - name: Regression tests
         id: regression_tests
         run: |
-          make PG_CONFIG=$HOME/pg12/bin/pg_config installcheck
+          make PG_CONFIG=$HOME/pg13/bin/pg_config installcheck
         continue-on-error: true
 
       - name: Dump regression test errors
diff --git a/.github/workflows/jdbc-driver.yaml 
b/.github/workflows/jdbc-driver.yaml
index d76ce6fa..02ad8f35 100644
--- a/.github/workflows/jdbc-driver.yaml
+++ b/.github/workflows/jdbc-driver.yaml
@@ -2,10 +2,10 @@ name: JDBC Driver Tests
 
 on:
   push:
-    branches: [ "master", "PG12" ]
+    branches: [ "master", "PG13" ]
 
   pull_request:
-    branches: [ "master", "PG12" ]
+    branches: [ "master", "PG13" ]
 
 jobs:
   build:
@@ -28,14 +28,14 @@ jobs:
         if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
           if [[ "$GITHUB_REF" == "refs/heads/master" ]]; then
             echo "TAG=latest" >> $GITHUB_ENV
-          elif [[ "$GITHUB_REF" == "refs/heads/PG12" ]]; then
-            echo "TAG=PG12_latest" >> $GITHUB_ENV
+          elif [[ "$GITHUB_REF" == "refs/heads/PG13" ]]; then
+            echo "TAG=PG13_latest" >> $GITHUB_ENV
           fi
         elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
           if [[ "$GITHUB_BASE_REF" == "master" ]]; then
             echo "TAG=latest" >> $GITHUB_ENV
-          elif [[ "$GITHUB_BASE_REF" == "PG12" ]]; then
-            echo "TAG=PG12_latest" >> $GITHUB_ENV
+          elif [[ "$GITHUB_BASE_REF" == "PG13" ]]; then
+            echo "TAG=PG13_latest" >> $GITHUB_ENV
           fi
         fi
 
diff --git a/.github/workflows/nodejs-driver.yaml 
b/.github/workflows/nodejs-driver.yaml
index b2a4e0ea..0d95af65 100644
--- a/.github/workflows/nodejs-driver.yaml
+++ b/.github/workflows/nodejs-driver.yaml
@@ -2,10 +2,10 @@ name: Nodejs Driver Tests
 
 on:
   push:
-    branches: [ "master", "PG12" ]
+    branches: [ "master", "PG13" ]
 
   pull_request:
-    branches: [ "master", "PG12" ]
+    branches: [ "master", "PG13" ]
 
 jobs:
   build:
@@ -23,14 +23,14 @@ jobs:
         if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
           if [[ "$GITHUB_REF" == "refs/heads/master" ]]; then
             echo "TAG=latest" >> $GITHUB_ENV
-          elif [[ "$GITHUB_REF" == "refs/heads/PG12" ]]; then
-            echo "TAG=PG12_latest" >> $GITHUB_ENV
+          elif [[ "$GITHUB_REF" == "refs/heads/PG13" ]]; then
+            echo "TAG=PG13_latest" >> $GITHUB_ENV
           fi
         elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
           if [[ "$GITHUB_BASE_REF" == "master" ]]; then
             echo "TAG=latest" >> $GITHUB_ENV
-          elif [[ "$GITHUB_BASE_REF" == "PG12" ]]; then
-            echo "TAG=PG12_latest" >> $GITHUB_ENV
+          elif [[ "$GITHUB_BASE_REF" == "PG13" ]]; then
+            echo "TAG=PG13_latest" >> $GITHUB_ENV
           fi
         fi
 
diff --git a/.github/workflows/python-driver.yaml 
b/.github/workflows/python-driver.yaml
index df3ed71b..af335e2f 100644
--- a/.github/workflows/python-driver.yaml
+++ b/.github/workflows/python-driver.yaml
@@ -2,10 +2,10 @@ name: Python Driver Tests
 
 on:
   push:
-    branches: [ "master", "PG12" ]
+    branches: [ "master", "PG13" ]
 
   pull_request:
-    branches: [ "master", "PG12" ]
+    branches: [ "master", "PG13" ]
 
 jobs:
   build:
@@ -23,14 +23,14 @@ jobs:
         if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
           if [[ "$GITHUB_REF" == "refs/heads/master" ]]; then
             echo "TAG=latest" >> $GITHUB_ENV
-          elif [[ "$GITHUB_REF" == "refs/heads/PG12" ]]; then
-            echo "TAG=PG12_latest" >> $GITHUB_ENV
+          elif [[ "$GITHUB_REF" == "refs/heads/PG13" ]]; then
+            echo "TAG=PG13_latest" >> $GITHUB_ENV
           fi
         elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
           if [[ "$GITHUB_BASE_REF" == "master" ]]; then
             echo "TAG=latest" >> $GITHUB_ENV
-          elif [[ "$GITHUB_BASE_REF" == "PG12" ]]; then
-            echo "TAG=PG12_latest" >> $GITHUB_ENV
+          elif [[ "$GITHUB_BASE_REF" == "PG13" ]]; then
+            echo "TAG=PG13_latest" >> $GITHUB_ENV
           fi
         fi
 
diff --git a/Dockerfile b/Dockerfile
index 24e1e2d9..031946c8 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -16,14 +16,14 @@
 # limitations under the License.
 #
 
-FROM postgres:12
+FROM postgres:13
 
 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-13
 
 COPY . /age
 RUN cd /age && make install
diff --git a/Makefile b/Makefile
index 759078fb..15247cb6 100644
--- a/Makefile
+++ b/Makefile
@@ -133,3 +133,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 de3a898a..63c82fff 100644
--- a/README.md
+++ b/README.md
@@ -33,8 +33,8 @@
     <img 
src="https://img.shields.io/badge/Release-v1.3.0-FFA500?labelColor=gray&style=flat&link=https://github.com/apache/age/releases"/>
   </a>
   &nbsp;
-  <a href="https://www.postgresql.org/docs/12/index.html";>
-    <img src="https://img.shields.io/badge/Version-PostgreSQL 
12-00008B?labelColor=gray&style=flat&link=https://www.postgresql.org/docs/12/index.html"/>
+  <a href="https://www.postgresql.org/docs/13/index.html";>
+    <img src="https://img.shields.io/badge/Version-PostgreSQL 
13-00008B?labelColor=gray&style=flat&link=https://www.postgresql.org/docs/13/index.html"/>
   </a>
   &nbsp;
   <a href="https://github.com/apache/age/issues";>
diff --git a/RELEASE b/RELEASE
index cb6f0de2..dd217fa8 100644
--- a/RELEASE
+++ b/RELEASE
@@ -15,13 +15,10 @@
 # specific language governing permissions and limitations
 # under the License.
 
-Release Notes for Apache AGE release v1.3.0 for PG 12
+Release Notes for Apache AGE release v1.3.0 for PG 13
 
 Apache AGE 1.3.0 - Release Notes
 
-NOTE: Due to additions to core tables, there is no upgrade path from the
-      previous version.
-
 Implement CALL ...[YIELD] for cypher functions. (#630)
 Graph names with the empty string '' are no more allowed. (#251)
 Fix typos at multiple locations. (#470)
@@ -46,7 +43,7 @@ Implement plus-equal operator in SET clause. (#638)
 Implement CI test for python driver. (#587)
 Move from travis CI to github actions for build. (#673)
 Update all driver CIs to Github actions.
-Fix build warnings.
+Fix build warnings. (#709)
 Updated Readme for drivers folder. (#642)
 Removed async from function definitions. (#680)
 Barbell graph generation (#648) and Barbell regress tests. (#708)
@@ -62,6 +59,6 @@ Fix property constraints against resolved variables. (#724) 
(#751) (#701) (#747)
 Include invalid labels in reused variables. (#751) (#762)
 Fix update_entity_tuple to use correct CommandId. (#769)
 Remove check for scalar agtypes in unwind. (#736)
-Update PG12 CI workflows. (#776)
+Update PG13 CI workflows. (#775)
 Update readme and version for python driver. (#780)
 Update README.md
diff --git a/age--1.3.0.sql b/age--1.3.0.sql
index b364ad3e..9022ac17 100644
--- a/age--1.3.0.sql
+++ b/age--1.3.0.sql
@@ -74,6 +74,7 @@ CREATE UNIQUE INDEX ag_label_relation_index ON ag_label USING 
btree (relation);
 CREATE UNIQUE INDEX ag_label_seq_name_graph_index
 ON ag_label
 USING btree (seq_name, graph);
+
 --
 -- catalog lookup functions
 --
@@ -109,21 +110,22 @@ CREATE FUNCTION ag_catalog.create_elabel(graph_name name, 
label_name name)
     LANGUAGE c
 AS 'MODULE_PATHNAME';
 
-CREATE FUNCTION ag_catalog.alter_graph(graph_name name, operation cstring, 
new_value name)
+CREATE FUNCTION ag_catalog.alter_graph(graph_name name, operation cstring,
+                                       new_value name)
 RETURNS void
 LANGUAGE c
 AS 'MODULE_PATHNAME';
 
 CREATE FUNCTION ag_catalog.drop_label(graph_name name, label_name name,
-                           force boolean = false)
+                                      force boolean = false)
 RETURNS void
 LANGUAGE c
 AS 'MODULE_PATHNAME';
 
 CREATE FUNCTION ag_catalog.load_labels_from_file(graph_name name,
-                                            label_name name,
-                                            file_path text,
-                                            id_field_exists bool default true)
+                                                 label_name name,
+                                                 file_path text,
+                                                 id_field_exists bool default 
true)
     RETURNS void
     LANGUAGE c
     AS 'MODULE_PATHNAME';
@@ -1389,7 +1391,6 @@ CREATE OPERATOR ^ (
   RIGHTARG = agtype
 );
 
-
 CREATE FUNCTION ag_catalog.graphid_hash_cmp(graphid)
 RETURNS INTEGER
 LANGUAGE c
@@ -3086,7 +3087,6 @@ CREATE CAST (agtype AS graphid)
 WITH FUNCTION ag_catalog.agtype_to_graphid(agtype)
 AS IMPLICIT;
 
-
 --
 -- agtype - path
 --
@@ -3425,6 +3425,7 @@ AS 'MODULE_PATHNAME';
 --
 -- Scalar Functions
 --
+
 CREATE FUNCTION ag_catalog.age_id(agtype)
 RETURNS agtype
 LANGUAGE c
@@ -4109,7 +4110,6 @@ CALLED ON NULL INPUT
 PARALLEL SAFE
 AS 'MODULE_PATHNAME';
 
-
 -- function to create an AGTV_PATH from a VLE_path_container
 CREATE FUNCTION ag_catalog.age_materialize_vle_path(agtype)
 RETURNS agtype
@@ -4136,7 +4136,6 @@ RETURNS NULL ON NULL INPUT
 PARALLEL SAFE
 AS 'MODULE_PATHNAME';
 
-
 CREATE FUNCTION ag_catalog.age_match_two_vle_edges(agtype, agtype)
 RETURNS boolean
 LANGUAGE C
@@ -4204,7 +4203,9 @@ STABLE
 PARALLEL SAFE
 AS 'MODULE_PATHNAME';
 
-CREATE FUNCTION ag_catalog.create_complete_graph(graph_name name, nodes int, 
edge_label name, node_label name = NULL)
+CREATE FUNCTION ag_catalog.create_complete_graph(graph_name name, nodes int,
+                                                 edge_label name,
+                                                 node_label name = NULL)
 RETURNS void
 LANGUAGE c
 CALLED ON NULL INPUT
@@ -4212,12 +4213,12 @@ PARALLEL SAFE
 AS 'MODULE_PATHNAME';
 
 CREATE FUNCTION ag_catalog.age_create_barbell_graph(graph_name name,
-                                                graph_size int,
-                                                bridge_size int,
-                                                node_label name = NULL,
-                                                node_properties agtype = NULL,
-                                                edge_label name = NULL,
-                                                edge_properties agtype = NULL)
+                                                    graph_size int,
+                                                    bridge_size int,
+                                                    node_label name = NULL,
+                                                    node_properties agtype = 
NULL,
+                                                    edge_label name = NULL,
+                                                    edge_properties agtype = 
NULL)
 RETURNS void
 LANGUAGE c
 CALLED ON NULL INPUT
diff --git a/drivers/golang/age/builder.go b/drivers/golang/age/builder.go
index 73bae701..43024a39 100644
--- a/drivers/golang/age/builder.go
+++ b/drivers/golang/age/builder.go
@@ -24,7 +24,6 @@ import (
        "math/big"
        "strconv"
        "strings"
-
        "github.com/antlr/antlr4/runtime/Go/antlr/v4"
        "github.com/apache/age/drivers/golang/parser"
 )
diff --git a/drivers/golang/age/mapper.go b/drivers/golang/age/mapper.go
index 987d3c94..1744e53a 100644
--- a/drivers/golang/age/mapper.go
+++ b/drivers/golang/age/mapper.go
@@ -22,7 +22,6 @@ import (
        "fmt"
        "reflect"
        "strings"
-
        "github.com/antlr/antlr4/runtime/Go/antlr/v4"
        "github.com/apache/age/drivers/golang/parser"
 )
diff --git a/regress/sql/cypher_call.sql b/regress/sql/cypher_call.sql
index 236b0e7a..91727680 100644
--- a/regress/sql/cypher_call.sql
+++ b/regress/sql/cypher_call.sql
@@ -38,7 +38,6 @@ CREATE FUNCTION call_stmt_test.add_agtype(agtype, agtype) 
RETURNS agtype
 /*
  * CALL (solo)
  */
-
 SELECT * FROM cypher('cypher_call', $$CALL sqrt(64)$$) as (sqrt agtype);
 /*  CALL RETURN, should fail */
 SELECT * FROM cypher('cypher_call', $$CALL sqrt(64) RETURN sqrt$$) as (sqrt 
agtype); 
diff --git a/src/backend/catalog/ag_catalog.c b/src/backend/catalog/ag_catalog.c
index e74be5aa..2004f4d7 100644
--- a/src/backend/catalog/ag_catalog.c
+++ b/src/backend/catalog/ag_catalog.c
@@ -42,7 +42,7 @@ static void object_access(ObjectAccessType access, Oid 
class_id, Oid object_id,
 void ag_ProcessUtility_hook(PlannedStmt *pstmt, const char *queryString,
                             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);
@@ -89,16 +89,16 @@ void process_utility_hook_fini(void)
 void ag_ProcessUtility_hook(PlannedStmt *pstmt, const char *queryString,
                              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);
+                                      queryEnv, dest, qc);
     else
         standard_ProcessUtility(pstmt, queryString, context, params, queryEnv,
-                                dest, completionTag);
+                                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 39e9dce3..bc0f74c8 100644
--- a/src/backend/commands/label_commands.c
+++ b/src/backend/commands/label_commands.c
@@ -619,6 +619,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);
@@ -639,7 +640,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 4b481092..560d110b 100644
--- a/src/backend/executor/cypher_create.c
+++ b/src/backend/executor/cypher_create.c
@@ -45,10 +45,11 @@ 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);
 
@@ -161,14 +162,14 @@ static void 
process_pattern(cypher_create_custom_scan_state *css)
     foreach (lc2, css->pattern)
     {
         cypher_create_path *path = lfirst(lc2);
-
-        ListCell *lc = list_head(path->target_nodes);
+        List *list = path->target_nodes;
+        ListCell *lc = list_head(list);
 
         /*
          * 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(list, lc), list);
 
         /*
          * If this path is a variable, take the list that was accumulated
@@ -339,7 +340,7 @@ 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;
@@ -360,7 +361,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
@@ -458,7 +459,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;
@@ -610,7 +611,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_merge.c 
b/src/backend/executor/cypher_merge.c
index c386e652..ab9d4ed9 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);
@@ -208,14 +208,14 @@ static bool check_path(cypher_merge_custom_scan_state 
*css,
 static void process_path(cypher_merge_custom_scan_state *css)
 {
     cypher_create_path *path = css->path;
-    ListCell *lc = list_head(path->target_nodes);
+    List *list = path->target_nodes;
+    ListCell *lc = list_head(list);
 
     /*
      * 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(list, lc), list);
 
     /*
      * If this path is a variable, take the list that was accumulated
@@ -629,7 +629,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;
@@ -840,7 +840,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;
@@ -851,7 +851,7 @@ 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;
@@ -872,7 +872,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
diff --git a/src/backend/executor/cypher_set.c 
b/src/backend/executor/cypher_set.c
index 7a8ec9b3..52e16771 100644
--- a/src/backend/executor/cypher_set.c
+++ b/src/backend/executor/cypher_set.c
@@ -115,6 +115,7 @@ static HeapTuple update_entity_tuple(ResultRelInfo 
*resultRelInfo,
     TM_Result   result;
     CommandId cid = GetCurrentCommandId(true);
     ResultRelInfo *saved_resultRelInfo = estate->es_result_relation_info;
+
     estate->es_result_relation_info = resultRelInfo;
 
     lockmode = ExecUpdateLockMode(estate, resultRelInfo);
diff --git a/src/backend/parser/ag_scanner.l b/src/backend/parser/ag_scanner.l
index 68b15a22..18ce042c 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 87458510..a7895900 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"
@@ -68,11 +69,11 @@ static const char *expr_get_const_cstring(Node *expr, const 
char *source_str);
 static int get_query_location(const int location, const char *source_str);
 static Query *analyze_cypher(List *stmt, ParseState *parent_pstate,
                              const char *query_str, int query_loc,
-                             char *graph_name, Oid graph_oid, Param *params);
+                             char *graph_name, uint32 graph_oid, Param 
*params);
 static Query *analyze_cypher_and_coerce(List *stmt, RangeTblFunction *rtfunc,
                                         ParseState *parent_pstate,
                                         const char *query_str, int query_loc,
-                                        char *graph_name, Oid graph_oid,
+                                        char *graph_name, uint32 graph_oid,
                                         Param *params);
 
 
@@ -620,7 +621,7 @@ static int get_query_location(const int location, const 
char *source_str)
 
 static Query *analyze_cypher(List *stmt, ParseState *parent_pstate,
                              const char *query_str, int query_loc,
-                             char *graph_name, Oid graph_oid, Param *params)
+                             char *graph_name, uint32 graph_oid, Param *params)
 {
     cypher_clause *clause;
     ListCell *lc;
@@ -699,14 +700,14 @@ static Query *analyze_cypher(List *stmt, ParseState 
*parent_pstate,
 static Query *analyze_cypher_and_coerce(List *stmt, RangeTblFunction *rtfunc,
                                         ParseState *parent_pstate,
                                         const char *query_str, int query_loc,
-                                        char *graph_name, Oid graph_oid,
+                                        char *graph_name, uint32 graph_oid,
                                         Param *params)
 {
     ParseState *pstate;
     Query *query;
     const bool lateral = false;
     Query *subquery;
-    RangeTblEntry *rte;
+    ParseNamespaceItem *pnsi;
     int rtindex;
     ListCell *lt;
     ListCell *lc1;
@@ -753,13 +754,13 @@ 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);
 
@@ -809,9 +810,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;
diff --git a/src/backend/parser/cypher_clause.c 
b/src/backend/parser/cypher_clause.c
index f14c4998..81f5cbfc 100644
--- a/src/backend/parser/cypher_clause.c
+++ b/src/backend/parser/cypher_clause.c
@@ -142,8 +142,12 @@ 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, bool valid_label);
-static Node *make_vertex_expr(cypher_parsestate *cpstate, RangeTblEntry *rte);
-static Node *make_edge_expr(cypher_parsestate *cpstate, RangeTblEntry *rte);
+static bool match_check_valid_label(cypher_match *match,
+                                    cypher_parsestate *cpstate);
+static Node *make_vertex_expr(cypher_parsestate *cpstate,
+                              ParseNamespaceItem *pnsi);
+static Node *make_edge_expr(cypher_parsestate *cpstate,
+                            ParseNamespaceItem *pnsi);
 static Node *make_qual(cypher_parsestate *cpstate,
                            transform_entity *entity, char *name);
 static TargetEntry *
@@ -208,9 +212,6 @@ static void handle_prev_clause(cypher_parsestate *cpstate, 
Query *query,
                                cypher_clause *clause, bool first_rte);
 static TargetEntry *placeholder_target_entry(cypher_parsestate *cpstate,
                                              char *name);
-
-static List *makeTargetListFromRTE(ParseState *pstate, RangeTblEntry *rte);
-
 static Query *transform_cypher_sub_pattern(cypher_parsestate *cpstate,
                                            cypher_clause *clause);
 // set and remove clause
@@ -242,8 +243,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,
@@ -289,11 +290,12 @@ static Query 
*transform_cypher_call_subquery(cypher_parsestate *cpstate,
 #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,
-                                                          transform_method 
transform,
-                                                          cypher_clause 
*clause,
-                                                          Alias *alias,
-                                                          bool 
add_rte_to_query);
+static ParseNamespaceItem
+*transform_cypher_clause_as_subquery(cypher_parsestate *cpstate,
+                                     transform_method transform,
+                                     cypher_clause *clause,
+                                     Alias *alias,
+                                     bool add_rte_to_query);
 static Query *analyze_cypher_clause(transform_method transform,
                                     cypher_clause *clause,
                                     cypher_parsestate *parent_cpstate);
@@ -315,25 +317,26 @@ 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);
+                                        RangeTblEntry *rte);
 static FuncExpr *make_clause_func_expr(char *function_name,
                                        Node *clause_information);
 /* for VLE support */
-static RangeTblEntry *transform_RangeFunction(cypher_parsestate *cpstate,
-                                              RangeFunction *r);
+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,
-                                                    Node *n);
+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);
 
+static ParseNamespaceItem *find_pnsi(cypher_parsestate *cpstate, char 
*varname);
+
 /*
  * transform a cypher_clause
  */
@@ -471,8 +474,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;
 
@@ -533,11 +538,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,
-             lcm, cypher_union_statement->colTypmods,
-             lcc, cypher_union_statement->colCollations)
+    forfour(lct, cypher_union_statement->colTypes,
+            lcm, cypher_union_statement->colTypmods,
+            lcc, cypher_union_statement->colCollations,
+            left_tlist, leftmostQuery->targetList)
     {
         Oid colType = lfirst_oid(lct);
         int32 colTypmod = lfirst_int(lcm);
@@ -563,7 +571,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++;
     }
 
     /*
@@ -578,18 +593,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, 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);
 
@@ -659,6 +671,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();
@@ -776,12 +789,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,
-                                            returnQuery,
-                                            makeAlias(returnName, NIL),
-                                            false,
-                                            false);
-
+        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);
@@ -1032,8 +1045,8 @@ transform_cypher_union_tree(cypher_parsestate *cpstate, 
cypher_clause *clause,
  * be picked up by the grammar. transform_cypher_call_subquery handles the
  * call transformation itself.
  */
-static Query * transform_cypher_call_stmt(cypher_parsestate *cpstate,
-                                          cypher_clause *clause)
+static Query *transform_cypher_call_stmt(cypher_parsestate *cpstate,
+                                         cypher_clause *clause)
 {
     ParseState *pstate = (ParseState *)cpstate;
     cypher_call *self = (cypher_call *)clause->self;
@@ -1309,19 +1322,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);
@@ -1338,7 +1351,6 @@ static Query *transform_cypher_unwind(cypher_parsestate 
*cpstate,
 
     unwind = makeFuncCall(list_make1(makeString("age_unnest")), NIL, -1);
 
-
     old_expr_kind = pstate->p_expr_kind;
     pstate->p_expr_kind = EXPR_KIND_SELECT_TARGET;
     funcexpr = ParseFuncOrColumn(pstate, unwind->funcname,
@@ -2272,9 +2284,11 @@ static bool match_check_valid_label(cypher_match *match,
 
     return true;
 }
+
 static Query *transform_cypher_clause_with_where(cypher_parsestate *cpstate,
                                                  transform_method transform,
-                                                 cypher_clause *clause, Node 
*where)
+                                                 cypher_clause *clause,
+                                                 Node *where)
 {
     ParseState *pstate = (ParseState *)cpstate;
     Query *query;
@@ -2283,23 +2297,24 @@ 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
 
         /*
-         * add all the target entries in rte to the current target list to pass
+         * add all the target entries in pnsi to the current target list to 
pass
          * all the variables that are introduced in the previous clause to the
          * next clause
          */
-        query->targetList = expandRelAttrs(pstate, rte, rtindex, 0, -1);
+        query->targetList = expandNSItemAttrs(pstate, pnsi, 0, -1);
 
         markTargetListOrigins(pstate, query->targetList);
 
@@ -2307,13 +2322,11 @@ static Query 
*transform_cypher_clause_with_where(cypher_parsestate *cpstate,
 
         if (!is_ag_node(self, cypher_match))
         {
-            where_qual = transform_cypher_expr(cpstate, where,
-                                                        EXPR_KIND_WHERE);
+            where_qual = transform_cypher_expr(cpstate, where, 
EXPR_KIND_WHERE);
 
-            where_qual = coerce_to_boolean(pstate, where_qual,
-                                            "WHERE");
+            where_qual = coerce_to_boolean(pstate, where_qual, "WHERE");
         }
-        
+
         query->jointree = makeFromExpr(pstate->p_joinlist, where_qual);
         assign_query_collations(pstate, query);
     }
@@ -2351,7 +2364,7 @@ static Query *transform_cypher_match(cypher_parsestate 
*cpstate,
     }
 
     return transform_cypher_clause_with_where(
-        cpstate, transform_cypher_match_pattern, clause, 
+        cpstate, transform_cypher_match_pattern, clause,
         match_self->where);
 }
 
@@ -2366,17 +2379,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;
 }
@@ -2389,8 +2400,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;
@@ -2399,9 +2410,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.
@@ -2447,14 +2458,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;
@@ -2492,12 +2502,20 @@ 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);
+    get_res_cols(pstate, l_nsitem, r_nsitem, &res_colnames, &res_colvars);
 
-    rte = addRangeTableEntryForJoin(pstate, res_colnames, j->jointype,
-                                    res_colvars, j->alias, true);
+    jnsitem = addRangeTableEntryForJoin(pstate,
+                                        res_colnames,
+                                        NULL,
+                                        j->jointype,
+                                        0,
+                                        res_colvars,
+                                        NIL,
+                                        NIL,
+                                        j->alias,
+                                        false);
 
-    j->rtindex = RTERangeTablePosn(pstate, rte, NULL);
+    j->rtindex = jnsitem->p_rtindex;
 
     for (i = list_length(pstate->p_joinexprs) + 1; i < j->rtindex; i++)
     {
@@ -2508,10 +2526,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,
@@ -2557,8 +2575,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
 
@@ -2567,7 +2587,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);
@@ -2615,18 +2636,21 @@ 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);
@@ -2657,7 +2681,7 @@ static List *makeTargetListFromRTE(ParseState *pstate, 
RangeTblEntry *rte)
         targetlist = lappend(targetlist, tmp);
 
         varattno++;
-        ln = lnext(ln);
+        ln = lnext(rte->eref->colnames, ln);
     }
 
     return targetlist;
@@ -2673,10 +2697,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;
@@ -2695,11 +2718,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);
 
@@ -2742,17 +2765,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;
@@ -2786,8 +2809,8 @@ 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,
-                                                    Node *n)
+static ParseNamespaceItem *append_VLE_Func_to_FromClause(cypher_parsestate 
*cpstate,
+                                                         Node *n)
 {
     ParseState *pstate = &cpstate->pstate;
     RangeTblEntry *rte = NULL;
@@ -2816,7 +2839,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));
 }
 
 /*
@@ -2824,7 +2847,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;
@@ -2832,8 +2855,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;
 
@@ -2902,9 +2925,11 @@ 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,
-                                        coldeflists, r, is_lateral, true);
-    return rte;
+    pnsi = addRangeTableEntryForFunction(pstate, funcnames, funcexprs,
+                                         coldeflists, r, is_lateral,
+                                         true);
+
+    return pnsi;
 }
 
 static void transform_match_pattern(cypher_parsestate *cpstate, Query *query,
@@ -3509,7 +3534,7 @@ static A_Expr 
*filter_vertices_on_label_id(cypher_parsestate *cpstate,
 
 /*
  * Creates the Contains operator to process property constraints for a vertex/
- * edge in a MATCH clause. creates the agtype @> with the entity's properties
+ * edge in a MATCH clause. Creates the agtype @> with the entity's properties
  * on the right and the constraints in the MATCH clause on the left.
  */
 static Node *create_property_constraints(cypher_parsestate *cpstate,
@@ -3520,8 +3545,8 @@ static Node 
*create_property_constraints(cypher_parsestate *cpstate,
     ParseState *pstate = (ParseState *)cpstate;
     char *entity_name;
     Node *const_expr;
-    RangeTblEntry *rte;
     Node *last_srf = pstate->p_last_srf;
+    ParseNamespaceItem *pnsi;
 
     /*
      * If the prop_expr node wasn't passed in, create it. Otherwise, skip
@@ -3537,12 +3562,11 @@ static Node 
*create_property_constraints(cypher_parsestate *cpstate,
                                 makeString("properties"));
 
         /* use Postgres to get the properties' transform node */
-        rte = find_rte(cpstate, entity_name);
-        if (rte != NULL)
+        pnsi = find_pnsi(cpstate, entity_name);
+        if (pnsi != NULL)
         {
-            prop_expr = scanRTEForColumn(pstate, rte,
-                                         AG_VERTEX_COLNAME_PROPERTIES, -1, 0,
-                                         NULL);
+            prop_expr = scanNSItemForColumn(pstate, pnsi, 0,
+                                            AG_VERTEX_COLNAME_PROPERTIES, -1);
         }
         else
         {
@@ -3616,11 +3640,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));
@@ -3658,11 +3682,11 @@ 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);
+    var = scanNSItemForColumn(pstate, pnsi, 0, "edges", -1);
     Assert(var != NULL);
 
     /*
@@ -3754,7 +3778,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)
     {
@@ -4005,7 +4029,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))
                     {
@@ -4090,7 +4114,9 @@ static List *transform_match_entities(cypher_parsestate 
*cpstate, Query *query,
                     }
 
                     ((cypher_map*)rel->props)->keep_null = true;
-                    r = create_property_constraints(cpstate, entity, 
rel->props, prop_expr);
+                    r = create_property_constraints(cpstate, entity, 
rel->props,
+                                                    prop_expr);
+
                     cpstate->property_constraint_quals =
                         lappend(cpstate->property_constraint_quals, r);
                 }
@@ -4169,19 +4195,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);
             }
         }
@@ -4373,13 +4399,13 @@ static Expr *transform_cypher_edge(cypher_parsestate 
*cpstate,
     char *rel_name = NULL;
     RangeVar *label_range_var = NULL;
     Alias *alias = NULL;
-    RangeTblEntry *rte = NULL;
     int resno = -1;
     TargetEntry *te = NULL;
     transform_entity *entity = NULL;
     cypher_relationship *cr = NULL;
     Node *expr = NULL;
     bool refs_var = false;
+    ParseNamespaceItem *pnsi = NULL;
 
     /*
      * If we have an edge name, get any potential variable or column
@@ -4577,19 +4603,21 @@ 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++;
 
     if (valid_label)
     {
-        expr = make_edge_expr(cpstate, rte);
+        expr = make_edge_expr(cpstate, pnsi);
     }
     else
     {
@@ -4614,13 +4642,13 @@ static Expr *transform_cypher_node(cypher_parsestate 
*cpstate,
     char *rel_name = NULL;
     RangeVar *label_range_var = NULL;
     Alias *alias = NULL;
-    RangeTblEntry *rte = NULL;
     int resno = -1;
     TargetEntry *te = NULL;
     Expr *expr = NULL;
     transform_entity *entity = NULL;
     cypher_node *cn = NULL;
     bool refs_var = false;
+    ParseNamespaceItem *pnsi;
 
     /* if we have a node name, get any potential variable references */
     if (node->name != NULL)
@@ -4811,19 +4839,22 @@ 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++;
 
     if (valid_label)
     {
-        expr = (Expr *)make_vertex_expr(cpstate, rte);
+        expr = (Expr *)make_vertex_expr(cpstate, pnsi);
     }
     else
     {
@@ -4837,7 +4868,8 @@ 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)
 {
     ParseState *pstate = (ParseState *)cpstate;
     Oid label_name_func_oid;
@@ -4852,13 +4884,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);
@@ -4874,10 +4904,10 @@ 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);
+    args = list_make4(id, start_id, end_id, label_name_func_expr);
+    args = lappend(args, props);
 
     func_expr = makeFuncExpr(func_oid, AGTYPEOID, args, InvalidOid, InvalidOid,
                              COERCE_EXPLICIT_CALL);
@@ -4885,7 +4915,8 @@ 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)
 {
     ParseState *pstate = (ParseState *)cpstate;
     Oid label_name_func_oid;
@@ -4897,10 +4928,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);
@@ -4916,8 +4949,8 @@ 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);
 
@@ -4999,8 +5032,9 @@ static List 
*transform_cypher_create_pattern(cypher_parsestate *cpstate,
     {
         cypher_create_path *transformed_path;
 
-        transformed_path = transform_cypher_create_path(
-            cpstate, &query->targetList, lfirst(lc));
+        transformed_path = transform_cypher_create_path(cpstate,
+                                                        &query->targetList,
+                                                        lfirst(lc));
 
         transformed_pattern = lappend(transformed_pattern, transformed_path);
     }
@@ -5025,10 +5059,10 @@ transform_cypher_create_path(cypher_parsestate 
*cpstate, List **target_list,
         if (findTarget(*target_list, path->var_name) != NULL)
         {
             ereport(ERROR,
-                   (errcode(ERRCODE_DUPLICATE_ALIAS),
-                    errmsg("variable \"%s\" already exists",
+                    (errcode(ERRCODE_DUPLICATE_ALIAS),
+                     errmsg("variable \"%s\" already exists",
                             path->var_name),
-                    parser_errposition(pstate, path->location)));
+                     parser_errposition(pstate, path->location)));
         }
     }
 
@@ -5047,10 +5081,10 @@ transform_cypher_create_path(cypher_parsestate 
*cpstate, List **target_list,
                 if (node->name && strcmp(node->name, path->var_name) == 0)
                 {
                     ereport(ERROR,
-                           (errcode(ERRCODE_DUPLICATE_ALIAS),
-                            errmsg("variable \"%s\" already exists",
+                            (errcode(ERRCODE_DUPLICATE_ALIAS),
+                             errmsg("variable \"%s\" already exists",
                                     path->var_name),
-                            parser_errposition(pstate, path->location)));
+                             parser_errposition(pstate, path->location)));
                 }
                 rel->flags |= CYPHER_TARGET_NODE_IN_PATH_VAR;
             }
@@ -5075,10 +5109,10 @@ transform_cypher_create_path(cypher_parsestate 
*cpstate, List **target_list,
                 if (edge->name && strcmp(edge->name, path->var_name) == 0)
                 {
                     ereport(ERROR,
-                           (errcode(ERRCODE_DUPLICATE_ALIAS),
-                            errmsg("variable \"%s\" already exists",
+                            (errcode(ERRCODE_DUPLICATE_ALIAS),
+                             errmsg("variable \"%s\" already exists",
                                     path->var_name),
-                            parser_errposition(pstate, path->location)));
+                             parser_errposition(pstate, path->location)));
                 }
                 rel->flags |= CYPHER_TARGET_NODE_IN_PATH_VAR;
             }
@@ -5093,7 +5127,7 @@ transform_cypher_create_path(cypher_parsestate *cpstate, 
List **target_list,
         else
         {
             ereport(ERROR,
-                   (errmsg_internal("unrecognized node in create pattern")));
+                    (errmsg_internal("unrecognized node in create pattern")));
         }
     }
 
@@ -5138,6 +5172,7 @@ transform_create_cypher_edge(cypher_parsestate *cpstate, 
List **target_list,
     TargetEntry *te;
     char *alias;
     AttrNumber resno;
+    ParseNamespaceItem *pnsi;
 
     if (edge->label)
     {
@@ -5226,8 +5261,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
@@ -5247,7 +5283,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;
 }
@@ -5256,17 +5292,17 @@ static bool variable_exists(cypher_parsestate *cpstate, 
char *name)
 {
     ParseState *pstate = (ParseState *)cpstate;
     Node *id;
-    RangeTblEntry *rte;
+    ParseNamespaceItem *pnsi;
 
     if (name == NULL)
     {
         return false;
     }
 
-    rte = find_rte(cpstate, PREV_CYPHER_CLAUSE_ALIAS);
-    if (rte)
+    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;
     }
@@ -5452,6 +5488,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;
@@ -5495,8 +5532,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
@@ -5514,7 +5552,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)
     {
@@ -5605,7 +5643,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,
@@ -5617,6 +5655,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
@@ -5657,7 +5696,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
@@ -5679,7 +5719,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);
     }
@@ -5687,10 +5727,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;
 }
 
 /*
@@ -6002,12 +6042,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;
@@ -6059,13 +6098,14 @@ 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);
+    jnsitem = addRangeTableEntryForJoin(pstate, res_colnames, NULL, 
j->jointype,
+                                        0, res_colvars, NIL, NIL, j->alias,
+                                        true);
 
-    j->rtindex = RTERangeTablePosn(pstate, rte, NULL);
+    j->rtindex = jnsitem->p_rtindex;
 
     /*
      * The index of a node in the p_joinexpr list is expected to match the
@@ -6085,19 +6125,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
@@ -6408,6 +6443,7 @@ transform_merge_cypher_edge(cypher_parsestate *cpstate, 
List **target_list,
     Relation label_relation;
     RangeVar *rv;
     RangeTblEntry *rte;
+    ParseNamespaceItem *pnsi;
 
     if (edge->name != NULL)
     {
@@ -6492,8 +6528,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,
-                                        AccessShareLock, NULL, false, false);
+    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
@@ -6504,7 +6541,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;
 }
@@ -6521,6 +6558,7 @@ transform_merge_cypher_node(cypher_parsestate *cpstate, 
List **target_list,
     Relation label_relation;
     RangeVar *rv;
     RangeTblEntry *rte;
+    ParseNamespaceItem *pnsi;
 
     if (node->name != NULL)
     {
@@ -6610,8 +6648,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,
-                                        AccessShareLock, NULL, false, false);
+    pnsi = addRangeTableEntryForRelation((ParseState *)cpstate, label_relation,
+                                         AccessShareLock, NULL, false, false);
+    rte = pnsi->p_rte;
     rte->requiredPerms = ACL_INSERT;
 
     // id
@@ -6621,7 +6660,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;
 }
@@ -6656,22 +6695,22 @@ static cypher_clause 
*convert_merge_to_match(cypher_merge *merge)
  * visible, whether the rte is only usable in lateral joins, and if the rte
  * is accessible in lateral joins.
  */
-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;
+    ParseNamespaceItem *nsitem = NULL;
+    ListCell *l;
 
-    return nsitem;
+    foreach(l, pstate->p_namespace)
+    {
+        nsitem = lfirst(l);
+        if (rte == nsitem->p_rte)
+        {
+            return nsitem;
+        }
+    }
+    Assert(nsitem != NULL);
+    return NULL;
 }
 
 /*
@@ -6719,10 +6758,11 @@ 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
@@ -6732,5 +6772,28 @@ 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;
 }
diff --git a/src/backend/parser/cypher_expr.c b/src/backend/parser/cypher_expr.c
index 62f7efde..31881f26 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"
@@ -93,8 +94,8 @@ 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,
-                                   int location);
+static Node *transform_WholeRowRef(ParseState *pstate, ParseNamespaceItem 
*pnsi,
+                                   int location, int sublevels_up);
 static ArrayExpr *make_agtype_array_expr(List *args);
 
 /* transform a cypher expression */
@@ -148,6 +149,7 @@ static Node 
*transform_cypher_expr_recurse(cypher_parsestate *cpstate,
             ereport(ERROR, (errmsg_internal("unrecognized A_Expr kind: %d",
                                             a->kind)));
         }
+        break;
     }
     case T_BoolExpr:
         return transform_BoolExpr(cpstate, (BoolExpr *)expr);
@@ -260,15 +262,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,
-                                   int location)
+static Node *transform_WholeRowRef(ParseState *pstate, ParseNamespaceItem 
*pnsi,
+                                   int location, int sublevels_up)
 {
     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
@@ -296,13 +301,13 @@ 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;
     char *nspname = NULL;
     char *relname = NULL;
     Node *node = NULL;
+    ParseNamespaceItem *pnsi = NULL;
     int levels_up;
 
     switch (list_length(cref->fields))
@@ -345,11 +350,12 @@ 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,
+                                                 levels_up);
                 }
                 else
                 {
@@ -362,7 +368,8 @@ static Node *transform_ColumnRef(cypher_parsestate 
*cpstate, ColumnRef *cref)
                 if (node == NULL)
                 {
                     ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
-                            errmsg("unable to transform whole row for %s", 
colname),
+                            errmsg("unable to transform whole row for %s",
+                                   colname),
                              parser_errposition(pstate, cref->location)));
                 }
 
@@ -385,9 +392,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),
@@ -403,15 +411,17 @@ 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,
+                                                 levels_up);
                     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,
@@ -620,9 +630,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);
 
diff --git a/src/backend/parser/cypher_item.c b/src/backend/parser/cypher_item.c
index 6eabb60e..6bcb4783 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,9 @@ 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));
     }
 
diff --git a/src/backend/parser/cypher_parse_agg.c 
b/src/backend/parser/cypher_parse_agg.c
index 8fdb71d3..47075ef7 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,8 @@ 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 307ad5be..6cc274d1 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 b2b34455..fec67615 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 bb154e3a..e4c12e84 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.c b/src/backend/utils/adt/agtype.c
index 43c1b205..3f26d183 100644
--- a/src/backend/utils/adt/agtype.c
+++ b/src/backend/utils/adt/agtype.c
@@ -2964,15 +2964,19 @@ static agtype_value *execute_map_access_operator(agtype 
*map,
     case AGTV_INTEGER:
         ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                         errmsg("AGTV_INTEGER is not a valid key type")));
+        break;
     case AGTV_FLOAT:
         ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                         errmsg("AGTV_FLOAT is not a valid key type")));
+        break;
     case AGTV_NUMERIC:
         ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                         errmsg("AGTV_NUMERIC is not a valid key type")));
+        break;
     case AGTV_BOOL:
         ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                         errmsg("AGTV_BOOL is not a valid key type")));
+        break;
     case AGTV_STRING:
         key_str = key_value->val.string.val;
         key_len = key_value->val.string.len;
@@ -5894,7 +5898,7 @@ static agtype_iterator 
*get_next_list_element(agtype_iterator *it,
 
     /* the next token should be an element or the end of the array */
     itok = agtype_iterator_next(&it, &tmp, true);
-    Assert(itok == WAGT_ELEM || WAGT_END_ARRAY);
+    Assert(itok == WAGT_ELEM || itok == WAGT_END_ARRAY);
 
     /* if this is the end of the array return NULL */
     if (itok == WAGT_END_ARRAY) {
@@ -9719,7 +9723,7 @@ static agtype_iterator 
*get_next_object_key(agtype_iterator *it,
 
     /* the next token should be a key or the end of the object */
     itok = agtype_iterator_next(&it, &tmp, false);
-    Assert(itok == WAGT_KEY || WAGT_END_OBJECT);
+    Assert(itok == WAGT_KEY || itok == WAGT_END_OBJECT);
     /* if this is the end of the object return NULL */
     if (itok == WAGT_END_OBJECT)
     {
diff --git a/src/backend/utils/adt/agtype_gin.c 
b/src/backend/utils/adt/agtype_gin.c
index 9a9adc9b..c0a2a028 100644
--- a/src/backend/utils/adt/agtype_gin.c
+++ b/src/backend/utils/adt/agtype_gin.c
@@ -48,7 +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
 
 /*
  *
diff --git a/src/backend/utils/cache/ag_cache.c 
b/src/backend/utils/cache/ag_cache.c
index 4fd4d13e..7759f56e 100644
--- a/src/backend/utils/cache/ag_cache.c
+++ b/src/backend/utils/cache/ag_cache.c
@@ -480,6 +480,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);
@@ -488,7 +489,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);
@@ -525,6 +528,12 @@ static void initialize_label_caches(void)
     ag_cache_scan_key_init(&label_seq_name_graph_scan_keys[1],
                            Anum_ag_label_graph, F_OIDEQ);
 
+    // ag_label.seq_name, ag_label.graph
+    ag_cache_scan_key_init(&label_seq_name_graph_scan_keys[0],
+                           Anum_ag_label_seq_name, F_NAMEEQ);
+    ag_cache_scan_key_init(&label_seq_name_graph_scan_keys[1],
+                           Anum_ag_label_graph, F_OIDEQ);
+
     create_label_caches();
 
     /*
@@ -928,7 +937,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);
@@ -1161,11 +1170,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/backend/utils/graph_generation.c 
b/src/backend/utils/graph_generation.c
index 7033c9bc..0d5d80aa 100644
--- a/src/backend/utils/graph_generation.c
+++ b/src/backend/utils/graph_generation.c
@@ -69,7 +69,6 @@ int64 get_nextval_internal(graph_cache_data* graph_cache,
     return nextval_internal(obj_seq_id, true);
 }
 
-
 PG_FUNCTION_INFO_V1(create_complete_graph);
 
 /*
diff --git a/src/backend/utils/load/ag_load_edges.c 
b/src/backend/utils/load/ag_load_edges.c
index ac4a6775..60f15f03 100644
--- a/src/backend/utils/load/ag_load_edges.c
+++ b/src/backend/utils/load/ag_load_edges.c
@@ -105,7 +105,6 @@ void edge_row_cb(int delim __attribute__((unused)), void 
*data)
         insert_edge_simple(cr->graph_oid, cr->object_name,
                            object_graph_id, start_vertex_graph_id,
                            end_vertex_graph_id, props);
-
     }
 
     for (i = 0; i < n_fields; ++i)
diff --git a/src/include/parser/cypher_parse_node.h 
b/src/include/parser/cypher_parse_node.h
index 5a9720d7..01377ab0 100644
--- a/src/include/parser/cypher_parse_node.h
+++ b/src/include/parser/cypher_parse_node.h
@@ -68,7 +68,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

Reply via email to