yugabyte / yugabyte-db

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.
https://www.yugabyte.com
Other
9.03k stars 1.08k forks source link

[YSQL][PostGIS] Segmentation fault in CatalogCacheComputeHashValue() #11323

Open def- opened 2 years ago

def- commented 2 years ago

Jira Link: DB-1220

Description

See https://docs.yugabyte.com/latest/api/ysql/extensions/#postgis for PostGIS installation instructions.

Can be reproduced against yugabyte-2.11.2.0 on CentOS using https://github.com/def-/postgis/tree/stable-3.1/regress by running PATH=$CWD/bin/:$PATH ./run_test.pl core/operators.sql

tserver log:

2022-02-01 09:31:19.990 UTC [4020] LOG:  server process (PID 5184) was terminated by signal 11: Segmentation fault
2022-02-01 09:31:19.990 UTC [4020] DETAIL:  Failed process was running: WITH v(i,g) AS ( VALUES
         (1,'POINT(0 0)'::geometry),
         (2,'POINTZ(0 0 1)'),
         (3,'POINTZ(0 0 0)'),
         (4,'POINTM(0 0 1)'),
         (5,'POINTZM(0 0 0 1)'),
         (6,'POINTZM(0 0 1 0)'),
         (7,'LINESTRINGM(-1 0 2,1 0 3)'),
         (8,'LINESTRINGZ(-1 0 2,1 0 3)'),
         (9,'LINESTRINGZM(-1 0 2 2,1 0 3 3)')
         )
        SELECT 'ndovm', v1.i, array_agg(v2.i) FROM v v1, v v2 WHERE v1.g &&& v2.g
        group by v1.i
        ORDER BY 2;

backtrace from gdb:

#0  0x0000000000000000 in ?? ()
#1  0x00000000009e2d47 in CatalogCacheComputeHashValue (v4=0, v3=1, v2=2, v1=0, nkeys=3, cache=0x3672700) at ../../../../../../../src/postgres/src/backend/utils/cache/catcache.c:306
#2  SearchCatCacheInternal (nkeys=3, v4=0, v3=<optimized out>, v2=<optimized out>, v1=<optimized out>, cache=0x3672700) at ../../../../../../../src/postgres/src/backend/utils/cache/catcache.c:1602
#3  SearchCatCache3 (cache=0x3672700, v1=0, v2=2, v3=1) at ../../../../../../../src/postgres/src/backend/utils/cache/catcache.c:1549
#4  0x00007fa9576cf64d in pg_get_nd_stats () from /nfusr/dev-server/dfelsing/yugabyte-2.11.2.0/postgres/lib/postgis-3.so
#5  0x00007fa9576d299d in gserialized_joinsel_internal () from /nfusr/dev-server/dfelsing/yugabyte-2.11.2.0/postgres/lib/postgis-3.so
#6  0x00007fa9576d2a43 in gserialized_gist_joinsel () from /nfusr/dev-server/dfelsing/yugabyte-2.11.2.0/postgres/lib/postgis-3.so
#7  0x0000000000a0f82d in DirectFunctionCall5Coll (func=0x7fa9576d2a00 <gserialized_gist_joinsel>, collation=<optimized out>, arg1=<optimized out>, arg2=<optimized out>, arg3=<optimized out>,
    arg4=<optimized out>, arg5=0) at ../../../../../../../src/postgres/src/backend/utils/fmgr/fmgr.c:918
#8  0x00007fa9576d28ca in gserialized_gist_joinsel_nd () from /nfusr/dev-server/dfelsing/yugabyte-2.11.2.0/postgres/lib/postgis-3.so
#9  0x0000000000a10dc8 in OidFunctionCall5Coll (functionId=<optimized out>, collation=collation@entry=0, arg1=arg1@entry=59713120, arg2=arg2@entry=330394, arg3=arg3@entry=59732280, arg4=arg4@entry=0,
    arg5=140720571111680) at ../../../../../../../src/postgres/src/backend/utils/fmgr/fmgr.c:1545
#10 0x00000000007c397b in join_selectivity (root=root@entry=0x38f2660, operatorid=330394, args=0x38f7138, inputcollid=0, jointype=jointype@entry=JOIN_INNER, sjinfo=sjinfo@entry=0x7ffc0fa75900)
    at ../../../../../../../src/postgres/src/backend/optimizer/util/plancat.c:1820
#11 0x000000000076c8f3 in clause_selectivity (root=root@entry=0x38f2660, clause=<optimized out>, varRelid=varRelid@entry=0, jointype=jointype@entry=JOIN_INNER, sjinfo=sjinfo@entry=0x7ffc0fa75900)
    at ../../../../../../../src/postgres/src/backend/optimizer/path/clausesel.c:739
#12 0x000000000076cadc in clauselist_selectivity (root=root@entry=0x38f2660, clauses=clauses@entry=0x38f97f8, varRelid=varRelid@entry=0, jointype=JOIN_INNER, sjinfo=sjinfo@entry=0x7ffc0fa75900)
    at ../../../../../../../src/postgres/src/backend/optimizer/path/clausesel.c:117
#13 0x000000000076df8a in calc_joinrel_size_estimate (root=0x38f2660, outer_rows=9, inner_rows=9, sjinfo=0x7ffc0fa75900, restrictlist_in=0x38f97f8, inner_rel=<optimized out>, outer_rel=<optimized out>,
    joinrel=<optimized out>) at ../../../../../../../src/postgres/src/backend/optimizer/path/costsize.c:4538
#14 0x0000000000773b8a in set_joinrel_size_estimates (root=root@entry=0x38f2660, rel=rel@entry=0x38f94f0, outer_rel=outer_rel@entry=0x38f7ba8, inner_rel=inner_rel@entry=0x38f7e58,
    sjinfo=sjinfo@entry=0x7ffc0fa75900, restrictlist=restrictlist@entry=0x38f97f8) at ../../../../../../../src/postgres/src/backend/optimizer/path/costsize.c:4393
#15 0x00000000007c6f20 in build_join_rel (root=root@entry=0x38f2660, joinrelids=joinrelids@entry=0x38f94d8, outer_rel=outer_rel@entry=0x38f7ba8, inner_rel=inner_rel@entry=0x38f7e58, sjinfo=0x7ffc0fa75900,
    restrictlist_ptr=restrictlist_ptr@entry=0x7ffc0fa758f8) at ../../../../../../../src/postgres/src/backend/optimizer/util/relnode.c:673
#16 0x0000000000781416 in make_join_rel (root=root@entry=0x38f2660, rel1=rel1@entry=0x38f7ba8, rel2=rel2@entry=0x38f7e58) at ../../../../../../../src/postgres/src/backend/optimizer/path/joinrels.c:730
#17 0x00000000007815ef in make_rels_by_clause_joins (other_rels=<optimized out>, old_rel=<optimized out>, root=<optimized out>) at ../../../../../../../src/postgres/src/backend/optimizer/path/joinrels.c:290
#18 join_search_one_level (root=root@entry=0x38f2660, level=level@entry=2) at ../../../../../../../src/postgres/src/backend/optimizer/path/joinrels.c:112
#19 0x000000000076be9b in standard_join_search (root=0x38f2660, levels_needed=2, initial_rels=<optimized out>) at ../../../../../../../src/postgres/src/backend/optimizer/path/allpaths.c:2822
#20 0x000000000076c307 in make_one_rel (root=root@entry=0x38f2660, joinlist=joinlist@entry=0x38f8128) at ../../../../../../../src/postgres/src/backend/optimizer/path/allpaths.c:227
#21 0x0000000000794dc0 in query_planner (root=root@entry=0x38f2660, tlist=tlist@entry=0x38f6d98, qp_callback=qp_callback@entry=0x795f00 <standard_qp_callback>, qp_extra=qp_extra@entry=0x7ffc0fa75bd0)
    at ../../../../../../../src/postgres/src/backend/optimizer/plan/planmain.c:265
#22 0x000000000079a10d in grouping_planner (root=root@entry=0x38f2660, inheritance_update=inheritance_update@entry=false, tuple_fraction=<optimized out>, tuple_fraction@entry=0)
    at ../../../../../../../src/postgres/src/backend/optimizer/plan/planner.c:1908
#23 0x000000000079ce2c in subquery_planner (glob=glob@entry=0x38f2b10, parse=parse@entry=0x38d2d70, parent_root=parent_root@entry=0x0, hasRecursion=hasRecursion@entry=false, tuple_fraction=tuple_fraction@entry=0)
    at ../../../../../../../src/postgres/src/backend/optimizer/plan/planner.c:966
#24 0x000000000079df25 in standard_planner (parse=0x38d2d70, cursorOptions=256, boundParams=<optimized out>) at ../../../../../../../src/postgres/src/backend/optimizer/plan/planner.c:405
#25 0x00007fa965c33ead in pg_hint_plan_planner (parse=0x38d2d70, cursorOptions=256, boundParams=0x0) at ../../../../../src/postgres/third-party-extensions/pg_hint_plan/pg_hint_plan.c:3221
#26 0x0000000000880324 in pg_plan_query (querytree=querytree@entry=0x38d2d70, cursorOptions=cursorOptions@entry=256, boundParams=boundParams@entry=0x0)
    at ../../../../../../src/postgres/src/backend/tcop/postgres.c:848
#27 0x0000000000880467 in pg_plan_queries (querytrees=<optimized out>, cursorOptions=cursorOptions@entry=256, boundParams=boundParams@entry=0x0) at ../../../../../../src/postgres/src/backend/tcop/postgres.c:914
#28 0x00000000008849e0 in exec_simple_query (
t\t\t\t\n (6,'POINTZM(0 0 1 0)'),\t\t\t\t\t\n (7,"..., query_string@entry=0x7ffc0fa76080 "Pa\247\017\374\177") at ../../../../../../src/postgres/src/backend/tcop/postgres.c:1089
#29 yb_exec_simple_query_impl (query_string=query_string@entry=0x358a118) at ../../../../../../src/postgres/src/backend/tcop/postgres.c:4434
#30 0x000000000087f8b8 in yb_exec_query_wrapper (exec_context=exec_context@entry=0x358a000, restart_data=restart_data@entry=0x7ffc0fa762b0, functor=functor@entry=0x884620 <yb_exec_simple_query_impl>,
    functor_context=functor_context@entry=0x358a118) at ../../../../../../src/postgres/src/backend/tcop/postgres.c:4419
#31 0x00000000008802ec in yb_exec_simple_query (
    query_string=query_string@entry=0x358a118 "WITH v(i,g) AS ( VALUES\n (1,'POINT(0 0)'::geometry),\t\t\t\n (2,'POINTZ(0 0 1)'),\t\t\t\t\t\n (3,'POINTZ(0 0 0)'),\t\t\t\t\t\n (4,'POINTM(0 0 1)'),\t\t\t\t\t\n (5,'POINTZM(0 0 0 1)'),\t\t\t\t\n (6,'POINTZM(0 0 1 0)'),\t\t\t\t\t\n (7,"..., exec_context=exec_context@entry=0x358a000) at ../../../../../../src/postgres/src/backend/tcop/postgres.c:4449
#32 0x0000000000882213 in PostgresMain (argc=<optimized out>, argv=argv@entry=0x35cc4d8, dbname=0x35cc3b8 "postgis_reg", username=0x3585fe8 "yugabyte")
    at ../../../../../../src/postgres/src/backend/tcop/postgres.c:5084
#33 0x000000000049e292 in BackendRun (port=0x3474960) at ../../../../../../src/postgres/src/backend/postmaster/postmaster.c:4470
#34 BackendStartup (port=0x3474960) at ../../../../../../src/postgres/src/backend/postmaster/postmaster.c:4136
#35 ServerLoop () at ../../../../../../src/postgres/src/backend/postmaster/postmaster.c:1754
#36 0x00000000007ea21f in PostmasterMain (argc=argc@entry=23, argv=argv@entry=0x334e000) at ../../../../../../src/postgres/src/backend/postmaster/postmaster.c:1417
#37 0x000000000073588a in PostgresServerProcessMain (argc=23, argv=0x334e000) at ../../../../../../src/postgres/src/backend/main/main.c:234
#38 0x0000000000735a89 in main ()

Same failure with core/regress_gist_index_nd.sql, core/regress_selectivity.sql, core/estimatedextent.sql, core/regress_spgist_index_2d.sql, core/regress_spgist_index_3d.sql, core/regress_spgist_index_nd.sql. Coredump: core.5184.zip

andrei-mart commented 2 years ago

Can not reproduce

yugabyte=# WITH v(i,g) AS ( VALUES
yugabyte(#          (1,'POINT(0 0)'::geometry),
yugabyte(#          (2,'POINTZ(0 0 1)'),
yugabyte(#          (3,'POINTZ(0 0 0)'),
yugabyte(#          (4,'POINTM(0 0 1)'),
yugabyte(#          (5,'POINTZM(0 0 0 1)'),
yugabyte(#          (6,'POINTZM(0 0 1 0)'),
yugabyte(#          (7,'LINESTRINGM(-1 0 2,1 0 3)'),
yugabyte(#          (8,'LINESTRINGZ(-1 0 2,1 0 3)'),
yugabyte(#          (9,'LINESTRINGZM(-1 0 2 2,1 0 3 3)')
yugabyte(#          )
yugabyte-#         SELECT 'ndovm', v1.i, array_agg(v2.i) FROM v v1, v v2 WHERE v1.g &&& v2.g
yugabyte-#         group by v1.i
yugabyte-#         ORDER BY 2;
 ?column? | i |      array_agg      
----------+---+---------------------
 ndovm    | 1 | {1,2,3,4,5,6,7,8,9}
 ndovm    | 2 | {1,2,4,6,7}
 ndovm    | 3 | {1,3,4,5,7}
 ndovm    | 4 | {1,2,3,4,5,8}
 ndovm    | 5 | {1,3,4,5}
 ndovm    | 6 | {1,2,6}
 ndovm    | 7 | {1,2,3,7,8,9}
 ndovm    | 8 | {1,4,7,8,9}
 ndovm    | 9 | {1,7,8,9}
(9 rows)

also see https://github.com/yugabyte/yugabyte-db/issues/11318#issuecomment-1040875605

def- commented 2 years ago

See my comment for full instructions: https://github.com/yugabyte/yugabyte-db/issues/11318#issuecomment-1042798619 Can still reproduce with:

$ PATH=$PWD/bin:/usr/pgsql-11/bin:$PATH POSTGIS_SCRIPTDIR=/usr/pgsql-11/share/contrib/postgis-3.1 ./run_test.pl core/operators.sql