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

Server crashes when executing SELECT * FROM cypher('list_comprehension' ...) #1850

Open
saygoodbyye opened this issue May 8, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@saygoodbyye
Copy link
Contributor

Describe the bug
Server crashes when executing the following SQL-script

How are you accessing AGE (Command line, driver, etc.)?
Accessing AGE through command line.

What data setup do we need to do?
Apache AGE (PG16 branch) with PostgreSQL (REL_16_STABLE).

What is the necessary configuration info needed?
My PostgreSQL configuration:

./configure CFLAGS=" -Og" --enable-tap-tests --enable-debug --enable-cassert

What is the command that caused the error?

CREATE EXTENSION age;
SET search_path TO ag_catalog;
SELECT create_graph('list_comprehension');
SELECT * FROM cypher('list_comprehension', $$ WITH [1, 2, 3] AS u UNWIND collect(u) AS v RETURN v $$) AS (u agtype);
SELECT * FROM cypher('list_comprehension', $$ MATCH(u {list: [0, 2, 4, 6, 8, 10, 12]}) WITh u, collect(u.list) AS v SET u += {b: [u IN range(0, 5)]} SET u.c = [u IN v[0]] RETURN u $$) AS (u agtype);

backtrace:

#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=140110869255104) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=140110869255104) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=140110869255104, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007f6e1c824476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007f6e1c80a7f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x000056309a7a4c24 in ExceptionalCondition (conditionName=conditionName@entry=0x56309a8fb478 "attnum >= 0 && attnum < outerslot->tts_nvalid", fileName=fileName@entry=0x56309a8fab27 "execExprInterp.c", lineNumber=lineNumber@entry=582) at assert.c:66
#6  0x000056309a46d4c1 in ExecInterpExpr (state=0x56309c452ce0, econtext=0x56309c451d70, isnull=0x7fffc5c16027) at execExprInterp.c:582
#7  0x000056309a469cae in ExecInterpExprStillValid (state=0x56309c452ce0, econtext=0x56309c451d70, isNull=0x7fffc5c16027) at execExprInterp.c:1870
#8  0x000056309a488e49 in ExecEvalExprSwitchContext (isNull=0x7fffc5c16027, econtext=0x56309c451d70, state=0x56309c452ce0) at ../../../src/include/executor/executor.h:355
#9  ExecProject (projInfo=0x56309c452cd8) at ../../../src/include/executor/executor.h:389
#10 project_aggregates (aggstate=aggstate@entry=0x56309c4518b8) at nodeAgg.c:1385
#11 0x000056309a489932 in agg_retrieve_direct (aggstate=aggstate@entry=0x56309c4518b8) at nodeAgg.c:2528
#12 0x000056309a489d72 in ExecAgg (pstate=0x56309c4518b8) at nodeAgg.c:2180
#13 0x000056309a47a94b in ExecProcNodeFirst (node=0x56309c4518b8) at execProcnode.c:464
#14 0x000056309a4afa95 in ExecProcNode (node=0x56309c4518b8) at ../../../src/include/executor/executor.h:273
#15 SubqueryNext (node=<optimized out>) at nodeSubqueryscan.c:53
#16 0x000056309a47dbd3 in ExecScanFetch (node=node@entry=0x56309c3da588, accessMtd=accessMtd@entry=0x56309a4afa74 <SubqueryNext>, recheckMtd=recheckMtd@entry=0x56309a4afa25 <SubqueryRecheck>) at execScan.c:132
#17 0x000056309a47dd64 in ExecScan (node=0x56309c3da588, accessMtd=accessMtd@entry=0x56309a4afa74 <SubqueryNext>, recheckMtd=recheckMtd@entry=0x56309a4afa25 <SubqueryRecheck>) at execScan.c:198
#18 0x000056309a4afa57 in ExecSubqueryScan (pstate=<optimized out>) at nodeSubqueryscan.c:87
#19 0x000056309a47a94b in ExecProcNodeFirst (node=0x56309c3da588) at execProcnode.c:464
#20 0x00007f6e1a60e614 in ExecProcNode (node=0x56309c3da588) at /tmp/pgsql/include/server/executor/executor.h:273
#21 exec_cypher_set (node=0x56309c3d9df8) at src/backend/executor/cypher_set.c:614
#22 0x000056309a48f4b4 in ExecCustomScan (pstate=0x56309c3d9df8) at nodeCustom.c:124
#23 0x000056309a47a94b in ExecProcNodeFirst (node=0x56309c3d9df8) at execProcnode.c:464
#24 0x000056309a4aa1b4 in ExecProcNode (node=0x56309c3d9df8) at ../../../src/include/executor/executor.h:273
#25 ExecNestLoop (pstate=0x56309c3d9bc8) at nodeNestloop.c:109
#26 0x000056309a47a94b in ExecProcNodeFirst (node=0x56309c3d9bc8) at execProcnode.c:464
#27 0x000056309a4861df in ExecProcNode (node=0x56309c3d9bc8) at ../../../src/include/executor/executor.h:273
#28 fetch_input_tuple (aggstate=aggstate@entry=0x56309c3d95f0) at nodeAgg.c:562
#29 0x000056309a489a9b in agg_retrieve_direct (aggstate=aggstate@entry=0x56309c3d95f0) at nodeAgg.c:2365
#30 0x000056309a489d72 in ExecAgg (pstate=0x56309c3d95f0) at nodeAgg.c:2180
#31 0x000056309a47a94b in ExecProcNodeFirst (node=0x56309c3d95f0) at execProcnode.c:464
#32 0x000056309a4afa95 in ExecProcNode (node=0x56309c3d95f0) at ../../../src/include/executor/executor.h:273
#33 SubqueryNext (node=<optimized out>) at nodeSubqueryscan.c:53
#34 0x000056309a47dbd3 in ExecScanFetch (node=node@entry=0x56309c3d9450, accessMtd=accessMtd@entry=0x56309a4afa74 <SubqueryNext>, recheckMtd=recheckMtd@entry=0x56309a4afa25 <SubqueryRecheck>) at execScan.c:132
#35 0x000056309a47dd64 in ExecScan (node=0x56309c3d9450, accessMtd=accessMtd@entry=0x56309a4afa74 <SubqueryNext>, recheckMtd=recheckMtd@entry=0x56309a4afa25 <SubqueryRecheck>) at execScan.c:198
#36 0x000056309a4afa57 in ExecSubqueryScan (pstate=<optimized out>) at nodeSubqueryscan.c:87
#37 0x000056309a47a94b in ExecProcNodeFirst (node=0x56309c3d9450) at execProcnode.c:464
#38 0x00007f6e1a60e614 in ExecProcNode (node=0x56309c3d9450) at /tmp/pgsql/include/server/executor/executor.h:273
#39 exec_cypher_set (node=0x56309c3d8c08) at src/backend/executor/cypher_set.c:614
#40 0x000056309a48f4b4 in ExecCustomScan (pstate=0x56309c3d8c08) at nodeCustom.c:124
#41 0x000056309a47a94b in ExecProcNodeFirst (node=0x56309c3d8c08) at execProcnode.c:464
#42 0x000056309a472f0e in ExecProcNode (node=0x56309c3d8c08) at ../../../src/include/executor/executor.h:273
#43 ExecutePlan (estate=estate@entry=0x56309c3d8918, planstate=0x56309c3d8c08, use_parallel_mode=<optimized out>, operation=operation@entry=CMD_SELECT, sendTuples=sendTuples@entry=true, numberTuples=numberTuples@entry=0, direction=ForwardScanDirection, dest=0x56309c483790, execute_once=true) at execMain.c:1670
#44 0x000056309a4730d1 in standard_ExecutorRun (queryDesc=0x56309c448bc8, direction=ForwardScanDirection, count=0, execute_once=<optimized out>) at execMain.c:365
#45 0x000056309a4731ab in ExecutorRun (queryDesc=queryDesc@entry=0x56309c448bc8, direction=direction@entry=ForwardScanDirection, count=count@entry=0, execute_once=<optimized out>) at execMain.c:309
#46 0x000056309a65a436 in PortalRunSelect (portal=portal@entry=0x56309c379008, forward=forward@entry=true, count=0, count@entry=9223372036854775807, dest=dest@entry=0x56309c483790) at pquery.c:924
#47 0x000056309a65bdd7 in PortalRun (portal=portal@entry=0x56309c379008, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, run_once=run_once@entry=true, dest=dest@entry=0x56309c483790, altdest=altdest@entry=0x56309c483790, qc=0x7fffc5c167a0) at pquery.c:768
#48 0x000056309a657eee in exec_simple_query (query_string=query_string@entry=0x56309c2fb618 "SELECT * FROM cypher('list_comprehension', $$ MATCH(u {list: [0, 2, 4, 6, 8, 10, 12]}) WITh u, collect(u.list) AS v SET u += {b: [u IN range(0, 5)]} SET u.c = [u IN v[0]] RETURN u $$) AS (u agtype);") at postgres.c:1274
#49 0x000056309a659d6f in PostgresMain (dbname=<optimized out>, username=<optimized out>) at postgres.c:4637
#50 0x000056309a5b1011 in BackendRun (port=port@entry=0x56309c32f180) at postmaster.c:4464
#51 0x000056309a5b40c8 in BackendStartup (port=port@entry=0x56309c32f180) at postmaster.c:4192
#52 0x000056309a5b4266 in ServerLoop () at postmaster.c:1782
#53 0x000056309a5b5777 in PostmasterMain (argc=argc@entry=3, argv=argv@entry=0x56309c2f5b90) at postmaster.c:1466
#54 0x000056309a4d2b93 in main (argc=3, argv=0x56309c2f5b90) at main.c:198

Expected behavior:
Expected ERROR to be shown or sql query to be succesfully executed

Best regards,
Egor Chindyaskin
Postgres Professional: https://postgrespro.com/

@saygoodbyye saygoodbyye added the bug Something isn't working label May 8, 2024
@jrgemignani
Copy link
Contributor

@MuhammadTahaNaveed

@MuhammadTahaNaveed MuhammadTahaNaveed self-assigned this May 8, 2024
@saygoodbyye
Copy link
Contributor Author

@MuhammadTahaNaveed, hello! One more crash on postgres REL_16_STABLE and Age PG16 on build without cassert.

./configure CFLAGS=" -Og" --enable-tap-tests --enable-debug

test.sql:

CREATE EXTENSION age;
SET search_path TO ag_catalog;

SELECT create_graph('list_comprehension');

SELECT * FROM cypher('list_comprehension', $$ MATCH(u {list: [0, 2, 4, 6, 8, 10, 12]}) WITh u, collect(u.list) AS v SET u += {b: [u IN range(0, 5)]} SET u.c = [u IN v[0]] RETURN u $$) AS (u agtype);
SELECT * FROM cypher('list_comprehension', $$ MATCH(u {list: [0, 2, 4, 6, 8, 10, 12]}) SET u.c = collect(u.list) RETURN u $$) AS (u agtype);

backtrace:

#0  MakeExpandedObjectReadOnlyInternal (d=0) at ../../../../src/include/postgres.h:314
#1  0x0000557a290fc397 in ExecInterpExpr (state=0x557a2b3cc9b0, econtext=0x557a2b3cbcb8, isnull=0x7fff2c6eb177) at execExprInterp.c:698
#2  0x0000557a290f9007 in ExecInterpExprStillValid (state=0x557a2b3cc9b0, econtext=0x557a2b3cbcb8, isNull=0x7fff2c6eb177) at execExprInterp.c:1870
#3  0x0000557a291137b6 in ExecEvalExprSwitchContext (isNull=0x7fff2c6eb177, econtext=0x557a2b3cbcb8, state=0x557a2b3cc9b0) at ../../../src/include/executor/executor.h:355
#4  ExecProject (projInfo=0x557a2b3cc9a8) at ../../../src/include/executor/executor.h:389
#5  project_aggregates (aggstate=aggstate@entry=0x557a2b3cb790) at nodeAgg.c:1385
#6  0x0000557a2911468e in agg_retrieve_direct (aggstate=aggstate@entry=0x557a2b3cb790) at nodeAgg.c:2528
#7  0x0000557a291148fe in ExecAgg (pstate=0x557a2b3cb790) at nodeAgg.c:2180
#8  0x0000557a291076ff in ExecProcNodeFirst (node=0x557a2b3cb790) at execProcnode.c:464
#9  0x0000557a29134676 in ExecProcNode (node=0x557a2b3cb790) at ../../../src/include/executor/executor.h:273
#10 SubqueryNext (node=<optimized out>) at nodeSubqueryscan.c:53
#11 0x0000557a2910a5d1 in ExecScanFetch (node=node@entry=0x557a2b3548a0, accessMtd=accessMtd@entry=0x557a29134655 <SubqueryNext>,
    recheckMtd=recheckMtd@entry=0x557a2913462b <SubqueryRecheck>) at execScan.c:132
#12 0x0000557a2910a748 in ExecScan (node=0x557a2b3548a0, accessMtd=accessMtd@entry=0x557a29134655 <SubqueryNext>, recheckMtd=recheckMtd@entry=0x557a2913462b <SubqueryRecheck>)
    at execScan.c:198
#13 0x0000557a29134650 in ExecSubqueryScan (pstate=<optimized out>) at nodeSubqueryscan.c:87
#14 0x0000557a291076ff in ExecProcNodeFirst (node=0x557a2b3548a0) at execProcnode.c:464
#15 0x00007fb469fd0c48 in ExecProcNode (node=0x557a2b3548a0) at /tmp/pgsql/include/server/executor/executor.h:273
#16 exec_cypher_set (node=0x557a2b354180) at src/backend/executor/cypher_set.c:614
#17 0x0000557a291193b1 in ExecCustomScan (pstate=0x557a2b354180) at nodeCustom.c:124
#18 0x0000557a291076ff in ExecProcNodeFirst (node=0x557a2b354180) at execProcnode.c:464
#19 0x0000557a2912fb4b in ExecProcNode (node=0x557a2b354180) at ../../../src/include/executor/executor.h:273
#20 ExecNestLoop (pstate=0x557a2b353f68) at nodeNestloop.c:109
#21 0x0000557a291076ff in ExecProcNodeFirst (node=0x557a2b353f68) at execProcnode.c:464
#22 0x0000557a2911135c in ExecProcNode (node=0x557a2b353f68) at ../../../src/include/executor/executor.h:273
#23 fetch_input_tuple (aggstate=aggstate@entry=0x557a2b3539b8) at nodeAgg.c:562
#24 0x0000557a291146e5 in agg_retrieve_direct (aggstate=aggstate@entry=0x557a2b3539b8) at nodeAgg.c:2365
#25 0x0000557a291148fe in ExecAgg (pstate=0x557a2b3539b8) at nodeAgg.c:2180
#26 0x0000557a291076ff in ExecProcNodeFirst (node=0x557a2b3539b8) at execProcnode.c:464
#27 0x0000557a29134676 in ExecProcNode (node=0x557a2b3539b8) at ../../../src/include/executor/executor.h:273
#28 SubqueryNext (node=<optimized out>) at nodeSubqueryscan.c:53
#29 0x0000557a2910a5d1 in ExecScanFetch (node=node@entry=0x557a2b353828, accessMtd=accessMtd@entry=0x557a29134655 <SubqueryNext>,
    recheckMtd=recheckMtd@entry=0x557a2913462b <SubqueryRecheck>) at execScan.c:132
#30 0x0000557a2910a748 in ExecScan (node=0x557a2b353828, accessMtd=accessMtd@entry=0x557a29134655 <SubqueryNext>, recheckMtd=recheckMtd@entry=0x557a2913462b <SubqueryRecheck>)
    at execScan.c:198
#31 0x0000557a29134650 in ExecSubqueryScan (pstate=<optimized out>) at nodeSubqueryscan.c:87
#32 0x0000557a291076ff in ExecProcNodeFirst (node=0x557a2b353828) at execProcnode.c:464
#33 0x00007fb469fd0c48 in ExecProcNode (node=0x557a2b353828) at /tmp/pgsql/include/server/executor/executor.h:273
#34 exec_cypher_set (node=0x557a2b353068) at src/backend/executor/cypher_set.c:614
#35 0x0000557a291193b1 in ExecCustomScan (pstate=0x557a2b353068) at nodeCustom.c:124
#36 0x0000557a291076ff in ExecProcNodeFirst (node=0x557a2b353068) at execProcnode.c:464
#37 0x0000557a29100e7a in ExecProcNode (node=0x557a2b353068) at ../../../src/include/executor/executor.h:273
#38 ExecutePlan (estate=estate@entry=0x557a2b352db0, planstate=0x557a2b353068, use_parallel_mode=<optimized out>, operation=operation@entry=CMD_SELECT, sendTuples=sendTuples@entry=true, numberTuples=numberTuples@entry=0, direction=ForwardScanDirection, dest=0x557a2b3f7aa0, execute_once=true) at execMain.c:1670
#39 0x0000557a29100fe0 in standard_ExecutorRun (queryDesc=0x557a2b3bf350, direction=ForwardScanDirection, count=0, execute_once=<optimized out>) at execMain.c:365
#40 0x0000557a291010be in ExecutorRun (queryDesc=queryDesc@entry=0x557a2b3bf350, direction=direction@entry=ForwardScanDirection, count=count@entry=0, execute_once=<optimized out>) at execMain.c:309
#41 0x0000557a292aa85d in PortalRunSelect (portal=portal@entry=0x557a2b2f4d30, forward=forward@entry=true, count=0, count@entry=9223372036854775807, dest=dest@entry=0x557a2b3f7aa0) at pquery.c:924
#42 0x0000557a292abe22 in PortalRun (portal=portal@entry=0x557a2b2f4d30, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, run_once=run_once@entry=true, dest=dest@entry=0x557a2b3f7aa0, altdest=altdest@entry=0x557a2b3f7aa0, qc=0x7fff2c6eb8d0) at pquery.c:768
#43 0x0000557a292a8364 in exec_simple_query (query_string=query_string@entry=0x557a2b2774a0 "SELECT * FROM cypher('list_comprehension', $$ MATCH(u {list: [0, 2, 4, 6, 8, 10, 12]}) WITh u, collect(u.list) AS v SET u += {b: [u IN range(0, 5)]} SET u.c = [u IN v[0]] RETURN u $$) AS (u agtype);") at postgres.c:1274
#44 0x0000557a292aa209 in PostgresMain (dbname=<optimized out>, username=<optimized out>) at postgres.c:4637
#45 0x0000557a2921bfad in BackendRun (port=port@entry=0x557a2b2aaee0) at postmaster.c:4464
#46 0x0000557a2921ed6f in BackendStartup (port=port@entry=0x557a2b2aaee0) at postmaster.c:4192
#47 0x0000557a2921ef0d in ServerLoop () at postmaster.c:1782
#48 0x0000557a292201f3 in PostmasterMain (argc=argc@entry=3, argv=argv@entry=0x557a2b271aa0) at postmaster.c:1466
#49 0x0000557a291540f6 in main (argc=3, argv=0x557a2b271aa0) at main.c:198

@MuhammadTahaNaveed
Copy link
Member

@MuhammadTahaNaveed, hello! One more crash on postgres REL_16_STABLE and Age PG16 on build without cassert.

hello @saygoodbyye

The issue is with the query that you have already reported before i.e.

SELECT * FROM cypher('list_comprehension', $$ MATCH(u {list: [0, 2, 4, 6, 8, 10, 12]}) WITh u, collect(u.list) AS v SET u += {b: [u IN range(0, 5)]} SET u.c = [u IN v[0]] RETURN u $$) AS (u agtype);

The following query is expected to return error and it does

issue_1850=# SELECT * FROM cypher('list_comprehension', $$ MATCH(u {list: [0, 2, 4, 6, 8, 10, 12]}) SET u.c = collect(u.list) RETURN u $$) AS (u agtype);
2024-05-10 15:00:58.312 PKT [44331] ERROR:  Invalid use of aggregation in this context at character 92
2024-05-10 15:00:58.312 PKT [44331] STATEMENT:  SELECT * FROM cypher('list_comprehension', $$ MATCH(u {list: [0, 2, 4, 6, 8, 10, 12]}) SET u.c = collect(u.list) RETURN u $$) AS (u agtype);
ERROR:  Invalid use of aggregation in this context
LINE 1: ..., $$ MATCH(u {list: [0, 2, 4, 6, 8, 10, 12]}) SET u.c = coll...
                                                             ^

I am working on a fix for the bug that you reported. I will update you as soon as I have an update or a fix.

AneeqaCodes added a commit to AneeqaCodes/age that referenced this issue May 13, 2024
Resolved server crashes related to list comprehension in Cypher queries, addressing issue apache#1850.
@diangamichael
Copy link

I think you should breakdown your complex query into simple blocks then execute one by one to isolate the error within the query

-- Create the extension and graph
CREATE EXTENSION age;
SET search_path TO ag_catalog;
SELECT create_graph('list_comprehension');

-- Test simpler Cypher queries
-- Step 1: Simple list comprehension
SELECT * FROM cypher('list_comprehension', $$ WITH [1, 2, 3] AS u RETURN u $$) AS (u agtype);

-- Step 2: Unwind a list
SELECT * FROM cypher('list_comprehension', $$ WITH [1, 2, 3] AS u UNWIND u AS v RETURN v $$) AS (v agtype);

If the simplified queries work increase the complexities step by step

-- Step 3: Collect a list
SELECT * FROM cypher('list_comprehension', $$ WITH [1, 2, 3] AS u UNWIND u AS v RETURN collect(v) $$) AS (collected agtype);

-- Step 4: Add matching and setting properties
SELECT * FROM cypher('list_comprehension', $$ CREATE (n {list: [0, 2, 4, 6, 8, 10, 12]}) RETURN n $$) AS (n agtype);

SELECT * FROM cypher('list_comprehension', $$ MATCH (n {list: [0, 2, 4, 6, 8, 10, 12]}) RETURN n $$) AS (n agtype);

SELECT * FROM cypher('list_comprehension', $$ MATCH (n {list: [0, 2, 4, 6, 8, 10, 12]}) WITH n, collect(n.list) AS v RETURN v $$) AS (v agtype);
with this you isolate the problematic query and rectify it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants