Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 1124: Segmentation fault when using specific tables #1125

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions regress/expected/expr.out
Original file line number Diff line number Diff line change
Expand Up @@ -6913,9 +6913,79 @@ SELECT * FROM cypher('graph_395', $$ MATCH (p:Project)-[:Has]->(t:Task)-[:Assign
{"pn": "Project B", "tasks": [{"tn": "Task C", "users": [{"id": 1407374883553282, "label": "Person", "properties": {"age": 43, "name": "Bob"}}::vertex]}]}
(2 rows)

---
--- Fix: Segmentation fault when using specific names for tables #1124
---
--- The following are just a few commands to test SQLValueFunction types
---
SELECT count(*) FROM CURRENT_ROLE;
count
-------
1
(1 row)

SELECT count(*) FROM CURRENT_USER;
count
-------
1
(1 row)

SELECT count(*) FROM USER;
count
-------
1
(1 row)

SELECT count(*) FROM SESSION_USER;
count
-------
1
(1 row)

SELECT * FROM CURRENT_CATALOG;
current_catalog
--------------------
contrib_regression
(1 row)

SELECT * FROM CURRENT_SCHEMA;
current_schema
----------------
ag_catalog
(1 row)

SELECT * FROM create_graph('issue_1124');
NOTICE: graph "issue_1124" has been created
create_graph
--------------

(1 row)

SELECT results, pg_typeof(user) FROM cypher('issue_1124', $$ CREATE (u) RETURN u $$) AS (results agtype), user;
results | pg_typeof
----------------------------------------------------------------+-----------
{"id": 281474976710657, "label": "", "properties": {}}::vertex | name
(1 row)

SELECT results, pg_typeof(user) FROM cypher('issue_1124', $$ MATCH (u) RETURN u $$) AS (results agtype), user;
results | pg_typeof
----------------------------------------------------------------+-----------
{"id": 281474976710657, "label": "", "properties": {}}::vertex | name
(1 row)

--
-- Cleanup
--
SELECT * FROM drop_graph('issue_1124', true);
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table issue_1124._ag_label_vertex
drop cascades to table issue_1124._ag_label_edge
NOTICE: graph "issue_1124" has been dropped
drop_graph
------------

(1 row)

SELECT * FROM drop_graph('graph_395', true);
NOTICE: drop cascades to 7 other objects
DETAIL: drop cascades to table graph_395._ag_label_vertex
Expand Down
18 changes: 18 additions & 0 deletions regress/sql/expr.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2810,9 +2810,27 @@ SELECT * FROM cypher('graph_395', $$ MATCH (p:Project)-[:Has]->(t:Task)-[:Assign
WITH p, collect(task) AS tasks
WITH {pn: p.name, tasks:tasks} AS project
RETURN project $$) AS (p agtype);

---
--- Fix: Segmentation fault when using specific names for tables #1124
---
--- The following are just a few commands to test SQLValueFunction types
---

SELECT count(*) FROM CURRENT_ROLE;
SELECT count(*) FROM CURRENT_USER;
SELECT count(*) FROM USER;
SELECT count(*) FROM SESSION_USER;
SELECT * FROM CURRENT_CATALOG;
SELECT * FROM CURRENT_SCHEMA;
SELECT * FROM create_graph('issue_1124');
SELECT results, pg_typeof(user) FROM cypher('issue_1124', $$ CREATE (u) RETURN u $$) AS (results agtype), user;
SELECT results, pg_typeof(user) FROM cypher('issue_1124', $$ MATCH (u) RETURN u $$) AS (results agtype), user;

--
-- Cleanup
--
SELECT * FROM drop_graph('issue_1124', true);
SELECT * FROM drop_graph('graph_395', true);
SELECT * FROM drop_graph('chained', true);
SELECT * FROM drop_graph('VLE', true);
Expand Down
30 changes: 30 additions & 0 deletions src/backend/parser/cypher_analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@ static bool convert_cypher_walker(Node *node, ParseState *pstate)
parser_errposition(pstate, exprLocation((Node *)funcexpr))));
}

/*
* From PG -
* SQLValueFunction - parameterless functions with special grammar
* productions.
*
* These are a special case that needs to be ignored.
*
* TODO: This likely needs to be done with XmlExpr types, and maybe
* a few others too.
*/
if (IsA(funcexpr, SQLValueFunction))
{
return false;
}

return expression_tree_walker((Node *)funcexpr->args,
convert_cypher_walker, pstate);
}
Expand Down Expand Up @@ -296,6 +311,21 @@ static bool is_rte_cypher(RangeTblEntry *rte)
*/
static bool is_func_cypher(FuncExpr *funcexpr)
{
/*
* From PG -
* SQLValueFunction - parameterless functions with special grammar
* productions.
*
* These are a special case that needs to be ignored.
*
* TODO: This likely needs to be done with XmlExpr types, and maybe
* a few others too.
*/
if (IsA(funcexpr, SQLValueFunction))
{
return false;
}

return is_oid_ag_func(funcexpr->funcid, "cypher");
}

Expand Down