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

PG16: Fix join recursion #6263

Merged
merged 2 commits into from
Nov 3, 2023
Merged

PG16: Fix join recursion #6263

merged 2 commits into from
Nov 3, 2023

Conversation

svenklemm
Copy link
Member

@svenklemm svenklemm commented Nov 2, 2023

Mark the EquivalenceMember for the compressed chunk as derived to
prevent an infinite recursion.

Disable-check: force-changelog-file
Disable-check: commit-count

Copy link

github-actions bot commented Nov 2, 2023

@mkindahl, @erimatnor: please review this pull request.

Powered by pull-review

@svenklemm svenklemm added the pg16 Issue/PR related to support for PG16 label Nov 2, 2023
Copy link

codecov bot commented Nov 2, 2023

Codecov Report

Merging #6263 (94d16cf) into main (7f25cd9) will decrease coverage by 0.04%.
Report is 2 commits behind head on main.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #6263      +/-   ##
==========================================
- Coverage   65.28%   65.25%   -0.04%     
==========================================
  Files         247      247              
  Lines       57486    57482       -4     
  Branches    12776    12765      -11     
==========================================
- Hits        37531    37511      -20     
- Misses      18068    18101      +33     
+ Partials     1887     1870      -17     
Files Coverage Δ
tsl/src/nodes/decompress_chunk/decompress_chunk.c 89.18% <100.00%> (+0.02%) ⬆️

... and 68 files with indirect coverage changes

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

@fabriziomello
Copy link
Contributor

fabriziomello commented Nov 2, 2023

The new code is leading to a segfault:

(gdb) bt full
#0  0x00007fa13e7727d6 in add_segmentby_to_equivalence_class (root=0x560321884768, cur_ec=0x560321889d78, info=0x56032185ba30, context=0x7fff809b3fd0) at /d/github.com/fabriziomello/timescaledb/tsl/src/nodes/decompress_chunk/decompress_chunk.c:1551
        em = 0x56032185d9b0
        ht_em = 0x0
        i = -1
        child_expr = 0x56032185d920
        new_relids = 0x56032185d990
        cur_em = 0x56032182ffd8
        var = 0x56032182fad8
        lc__state = {l = 0x560321830048, i = 0}
        uncompressed_chunk_relids = 0x560321888820
        lc = 0x560321830060
        compressed_fdw_private = 0x56032185cca0
#1  0x00007fa13e7729e8 in compressed_rel_setup_equivalence_classes (root=0x560321884768, info=0x56032185ba30) at /d/github.com/fabriziomello/timescaledb/tsl/src/nodes/decompress_chunk/decompress_chunk.c:1607
        cur_ec = 0x560321889d78
        em_added = false
        context = {compression_info = 0x56032185beb0, uncompressed_relid = 17315, compressed_relid = 17358, uncompressed_relid_idx = 2, compressed_relid_idx = 5, current_col_info = 0x56032185be20}
        i = 6
#2  0x00007fa13e772e0b in decompress_chunk_add_plannerinfo (root=0x560321884768, info=0x56032185ba30, chunk=0x560321889a28, chunk_rel=0x560321889290, needs_sequence_num=true) at /d/github.com/fabriziomello/timescaledb/tsl/src/nodes/decompress_chunk/decompress_chunk.c:1675
        compressed_index = 5
        compressed_fd = {id = 18, hypertable_id = 4, schema_name = {data = "_timescaledb_internal", '\000' <repeats 42 times>}, table_name = {data = "compress_hyper_4_18_chunk", '\000' <repeats 38 times>}, compressed_chunk_id = 0, dropped = false, status = 0, osm_chunk = false, creation_time = 0}
        compressed_reloid = 17358
        compression_hypertable_reloid = 17333
        compressed_rel = 0x56032185c818
        lc = 0x0
#3  0x00007fa13e770668 in ts_decompress_chunk_generate_paths (root=0x560321884768, chunk_rel=0x560321889290, ht=0x5603217dbfe8, chunk=0x560321889a28) at /d/github.com/fabriziomello/timescaledb/tsl/src/nodes/decompress_chunk/decompress_chunk.c:633
        compressed_rel = 0x7fff809b42c0
        lc = 0x5603217d9db0
        new_row_estimate = 6.9332488277679845e-310
        ht_relid = 0
        info = 0x56032185ba30
        sort_info = {compressed_pathkeys = 0x0, needs_sequence_num = true, can_pushdown_sort = false, reverse = false}
        initial_pathlist = 0x56032185b9d0
        initial_partial_pathlist = 0x0
        parent_relids = 0x5603217d9f18
#4  0x00007fa13e6f7ca8 in tsl_set_rel_pathlist_query (root=0x560321884768, rel=0x560321889290, rti=2, rte=0x560321879348, ht=0x5603217dbfe8) at /d/github.com/fabriziomello/timescaledb/tsl/src/planner.c:155
        fdw_private = 0x560321863e58
#5  0x00007fa13eb9b7cf in apply_optimizations (root=0x560321884768, reltype=TS_REL_CHUNK_STANDALONE, rel=0x560321889290, rte=0x560321879348, ht=0x5603217dbfe8) at /d/github.com/fabriziomello/timescaledb/src/planner/planner.c:1145
No locals.
#6  0x00007fa13eb9bf0d in timescaledb_set_rel_pathlist (root=0x560321884768, rel=0x560321889290, rti=2, rte=0x560321879348) at /d/github.com/fabriziomello/timescaledb/src/planner/planner.c:1300
        reltype = TS_REL_CHUNK_STANDALONE
        ht = 0x5603217dbfe8
#7  0x000056031f6a5170 in set_rel_pathlist (root=0x560321884768, rel=0x560321889290, rti=2, rte=0x560321879348) at allpaths.c:542
        __func__ = "set_rel_pathlist"
#8  0x000056031f6a4cd5 in set_base_rel_pathlists (root=0x560321884768) at allpaths.c:354
        rel = 0x560321889290
        rti = 2
#9  0x000056031f6a49f7 in make_one_rel (root=0x560321884768, joinlist=0x56032188bc48) at allpaths.c:224
        rel = 0x0
        rti = 4
        total_pages = 20
#10 0x000056031f6e7473 in query_planner (root=0x560321884768, qp_callback=0x56031f6edd75 <standard_qp_callback>, qp_extra=0x7fff809b4690) at planmain.c:278
        parse = 0x560321878c28
        joinlist = 0x56032188bc48
        final_rel = 0x560321878c28
        __func__ = "query_planner"
#11 0x000056031f6e9f62 in grouping_planner (root=0x560321884768, tuple_fraction=100) at planner.c:1495
        sort_input_targets = 0x0
        sort_input_target_parallel_safe = 128
        grouping_target = 0x121886218
        scanjoin_target = 0x560321846758
        activeWindows = 0x0
        qp_extra = {activeWindows = 0x0, gset_data = 0x0}
        sort_input_targets_contain_srfs = 0x0
        have_grouping = false
        wflists = 0x0
        gset_data = 0x0
        sort_input_target = 0x100000001
        grouping_targets = 0x560300000000
        grouping_target_parallel_safe = 255
        scanjoin_targets = 0x560321886188
        scanjoin_target_parallel_safe = 127
        grouping_targets_contain_srfs = 0x7fff809b46a0
        scanjoin_targets_contain_srfs = 0x0
        scanjoin_target_same_exprs = false
        parse = 0x560321878c28
        offset_est = 0
        count_est = 100
        limit_tuples = 100
        have_postponed_srfs = false
        final_target = 0x7fff809b45d0
        final_targets = 0x56032168a4f8
        final_targets_contain_srfs = 0x560321884768
        final_target_parallel_safe = 155
        current_rel = 0x56031f63259b <new_list+81>
        final_rel = 0x560321846758
        extra = {limit_needed = false, limit_tuples = 0, count_est = 0, offset_est = 0}
        lc = 0x7fff809b45f0
        __func__ = "grouping_planner"
#12 0x000056031f6e95e0 in subquery_planner (glob=0x5603217efa08, parse=0x560321878c28, parent_root=0x0, hasRecursion=false, tuple_fraction=0) at planner.c:1064
        root = 0x560321884768
        newWithCheckOptions = 0x0
        newHaving = 0x0
        hasOuterJoins = true
        hasResultRTEs = false
        final_rel = 0x560321878c28
        l = 0x0
#13 0x000056031f6e7b7c in standard_planner (parse=0x560321878c28, query_string=0x560321688e38 "EXPLAIN (costs off)\nSELECT *\nFROM _timescaledb_internal._hyper_3_13_chunk m1\n    LEFT OUTER JOIN _timescaledb_internal._hyper_3_13_chunk m2 ON m1.time = m2.time\n    AND m1.device_id = 1\n    AND m2.dev"..., cursorOptions=2048, boundParams=0x0) at planner.c:413
        result = 0x5603217dbed8
        glob = 0x5603217efa08
        tuple_fraction = 0
        root = 0x5c00000000
        final_rel = 0x7fff809b48c0
        best_path = 0x7fa13eb9a1df <preprocess_query+929>
        top_plan = 0x0
        lp = 0x7fff809b4880
        lr = 0x68fa88000000004
#14 0x00007fa13eb9a57b in timescaledb_planner (parse=0x560321878c28, query_string=0x560321688e38 "EXPLAIN (costs off)\nSELECT *\nFROM _timescaledb_internal._hyper_3_13_chunk m1\n    LEFT OUTER JOIN _timescaledb_internal._hyper_3_13_chunk m2 ON m1.time = m2.time\n    AND m1.device_id = 1\n    AND m2.dev"..., cursor_opts=2048, bound_params=0x0) at /d/github.com/fabriziomello/timescaledb/src/planner/planner.c:571
        context = {rootquery = 0x560321878c28, current_query = 0x560321878c28, root = 0x7fff809b4ac0, num_distributed_tables = 0}
        glob = {type = T_Invalid, boundParams = 0x0, subplans = 0x0, subroots = 0x0, rewindPlanIDs = 0x0, finalrtable = 0x0, finalrteperminfos = 0x0, finalrowmarks = 0x0, resultRelations = 0x0, appendRelations = 0x0, relationOids = 0x0, invalItems = 0x0, paramExecTypes = 0x0, lastPHId = 0, lastRowMarkId = 0, lastPlanNodeId = 0, transientPlan = false, dependsOnRole = false, parallelModeOK = false, parallelModeNeeded = false, maxParallelHazard = 0 '\000', partition_directory = 0x0}
        root = {type = T_Invalid, parse = 0x0, glob = 0x7fff809b4960, query_level = 0, parent_root = 0x0, plan_params = 0x0, outer_params = 0x0, simple_rel_array = 0x0, simple_rel_array_size = 0, simple_rte_array = 0x0, append_rel_array = 0x0, all_baserels = 0x0, outer_join_rels = 0x0, all_query_rels = 0x0, join_rel_list = 0x0, join_rel_hash = 0x0, join_rel_level = 0x0, join_cur_level = 0, init_plans = 0x0, cte_plan_ids = 0x0, multiexpr_params = 0x0, join_domains = 0x0, eq_classes = 0x0, ec_merging_done = false, canon_pathkeys = 0x0, left_join_clauses = 0x0, right_join_clauses = 0x0, full_join_clauses = 0x0, join_info_list = 0x0, last_rinfo_serial = 0, all_result_relids = 0x0, leaf_result_relids = 0x0, append_rel_list = 0x0, row_identity_vars = 0x0, rowMarks = 0x0, placeholder_list = 0x0, placeholder_array = 0x0, placeholder_array_size = 0, fkey_list = 0x0, query_pathkeys = 0x0, group_pathkeys = 0x0, num_groupby_pathkeys = 0, window_pathkeys = 0x0, distinct_pathkeys = 0x0, sort_pathkeys = 0x0, part_schemes = 0x0, initial_rels = 0x0, upper_rels = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, upper_targets = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, processed_groupClause = 0x0, processed_distinctClause = 0x0, processed_tlist = 0x0, update_colnos = 0x0, grouping_map = 0x0, minmax_aggs = 0x0, planner_cxt = 0x0, total_table_pages = 0, tuple_fraction = 0, limit_tuples = 0, qual_security_level = 0, hasJoinRTEs = false, hasLateralRTEs = false, hasHavingQual = false, hasPseudoConstantQuals = false, hasAlternativeSubPlans = false, placeholdersFrozen = false, hasRecursion = false, agginfos = 0x0, aggtransinfos = 0x0, numOrderedAggs = 0, hasNonPartialAggs = false, hasNonSerialAggs = false, wt_param_id = 0, non_recursive_path = 0x0, curOuterRels = 0x0, curOuterParams = 0x0, isAltSubplan = 0x0, isUsedSubplan = 0x0, join_search_private = 0x0, partColsUpdated = false}
        _save_exception_stack = 0x7fff809b54b0
        _save_context_stack = 0x0
        _local_sigjmp_buf = {{__jmpbuf = {0, 1897295901380811935, 94571445390904, 94571411324917, 94571419336248, 140330535481408, 1897295901206748319, 1939345908802100383}, __mask_was_saved = 0, __saved_mask = {__val = {94571445831624, 88057006784, 133143986176, 15042562688, 2, 94571447334848, 94571447336424, 13, 1576, 140735351049776, 94571415870264, 32, 94571445850768, 0, 8589934592, 94558562542496}}}}
        _do_rethrow = false
        stmt = 0x80
        lc = 0x5f8
        reset_fetcher_type = true
        reset_baserel_info = true
        __func__ = "timescaledb_planner"
#15 0x000056031f6e7896 in planner (parse=0x560321878c28, query_string=0x560321688e38 "EXPLAIN (costs off)\nSELECT *\nFROM _timescaledb_internal._hyper_3_13_chunk m1\n    LEFT OUTER JOIN _timescaledb_internal._hyper_3_13_chunk m2 ON m1.time = m2.time\n    AND m1.device_id = 1\n    AND m2.dev"..., cursorOptions=2048, boundParams=0x0) at planner.c:279
        result = 0x7fa13e8e566d <__GI___clock_gettime+29>
#16 0x000056031f8385da in pg_plan_query (querytree=0x560321878c28, query_string=0x560321688e38 "EXPLAIN (costs off)\nSELECT *\nFROM _timescaledb_internal._hyper_3_13_chunk m1\n    LEFT OUTER JOIN _timescaledb_internal._hyper_3_13_chunk m2 ON m1.time = m2.time\n    AND m1.device_id = 1\n    AND m2.dev"..., cursorOptions=2048, boundParams=0x0) at postgres.c:904
        plan = 0x68fa880458ce600
#17 0x000056031f4c0411 in ExplainOneQuery (query=0x560321878c28, cursorOptions=2048, into=0x0, es=0x56032180d418, queryString=0x560321688e38 "EXPLAIN (costs off)\nSELECT *\nFROM _timescaledb_internal._hyper_3_13_chunk m1\n    LEFT OUTER JOIN _timescaledb_internal._hyper_3_13_chunk m2 ON m1.time = m2.time\n    AND m1.device_id = 1\n    AND m2.dev"..., params=0x0, queryEnv=0x0) at explain.c:406
        planstart = {ticks = 128322090217712}
        bufusage = {shared_blks_hit = 140735351049984, shared_blks_read = 94571411483334, shared_blks_dirtied = 94571447421992, shared_blks_written = 94571447336440, local_blks_hit = 140735351050096, local_blks_read = 94571413151855, local_blks_dirtied = 94571445393936, local_blks_written = 94571447421992, temp_blks_read = 4311744514, temp_blks_written = 94571447336440, blk_read_time = {ticks = 0}, blk_write_time = {ticks = 0}, temp_blk_read_time = {ticks = 0}, temp_blk_write_time = {ticks = 94571447336392}}
        plan = 0x560321863df8
        planduration = {ticks = 94571445850768}
        bufusage_start = {shared_blks_hit = 4869, shared_blks_read = 94571445850768, shared_blks_dirtied = 94571447336440, shared_blks_written = 32, local_blks_hit = 0, local_blks_read = 0, local_blks_dirtied = 94571447429232, local_blks_written = 472781754773333504, temp_blks_read = 140735351049952, temp_blks_written = 94571411482011, blk_read_time = {ticks = 140330513269768}, blk_write_time = {ticks = 4294967297}, temp_blk_read_time = {ticks = 4857411576}, temp_blk_write_time = {ticks = 94571447336440}}
#18 0x000056031f4bff03 in ExplainQuery (pstate=0x56032180d558, stmt=0x56032168acb8, params=0x0, dest=0x5603216f94d0) at explain.c:290
        l__state = {l = 0x560321863df8, i = 0}
        l = 0x560321863e10
        es = 0x56032180d418
        tstate = 0xe0
        jstate = 0x0
        query = 0x560321878c28
        rewritten = 0x560321863df8
        lc = 0x0
        timing_set = false
        summary_set = false
        __func__ = "ExplainQuery"
#19 0x000056031f842bfa in standard_ProcessUtility (pstmt=0x560321878b18, queryString=0x560321688e38 "EXPLAIN (costs off)\nSELECT *\nFROM _timescaledb_internal._hyper_3_13_chunk m1\n    LEFT OUTER JOIN _timescaledb_internal._hyper_3_13_chunk m2 ON m1.time = m2.time\n    AND m1.device_id = 1\n    AND m2.dev"..., readOnlyTree=false, context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0x5603216f94d0, qc=0x7fff809b53f0) at utility.c:870
        parsetree = 0x56032168acb8
        isTopLevel = true
        isAtomicContext = false
        pstate = 0x56032180d558
        readonly_flags = 7
        __func__ = "standard_ProcessUtility"
#20 0x00007fa13fb38934 in loader_process_utility_hook (pstmt=0x560321878b18, query_string=0x560321688e38 "EXPLAIN (costs off)\nSELECT *\nFROM _timescaledb_internal._hyper_3_13_chunk m1\n    LEFT OUTER JOIN _timescaledb_internal._hyper_3_13_chunk m2 ON m1.time = m2.time\n    AND m1.device_id = 1\n    AND m2.dev"..., readonly_tree=false, context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0x5603216f94d0, completion_tag=0x7fff809b53f0) at /d/github.com/fabriziomello/timescaledb/src/loader/loader.c:639
        is_distributed_database = false
        dist_uuid = 0x0
        process_utility = 0x56031f842172 <standard_ProcessUtility>
        __func__ = "loader_process_utility_hook"
#21 0x00007fa13eb4d701 in prev_ProcessUtility (args=0x7fff809b5290) at /d/github.com/fabriziomello/timescaledb/src/process_utility.c:100
        hook = 0x7fa13fb387c6 <loader_process_utility_hook>
#22 0x00007fa13eb56f46 in timescaledb_ddl_command_start (pstmt=0x560321878b18, query_string=0x560321688e38 "EXPLAIN (costs off)\nSELECT *\nFROM _timescaledb_internal._hyper_3_13_chunk m1\n    LEFT OUTER JOIN _timescaledb_internal._hyper_3_13_chunk m2 ON m1.time = m2.time\n    AND m1.device_id = 1\n    AND m2.dev"..., readonly_tree=false, context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0x5603216f94d0, completion_tag=0x7fff809b53f0) at /d/github.com/fabriziomello/timescaledb/src/process_utility.c:4554
        args = {hcache = 0x0, pstmt = 0x560321878b18, queryEnv = 0x0, parse_state = 0x5603216f9560, parsetree = 0x56032168acb8, query_string = 0x560321688e38 "EXPLAIN (costs off)\nSELECT *\nFROM _timescaledb_internal._hyper_3_13_chunk m1\n    LEFT OUTER JOIN _timescaledb_internal._hyper_3_13_chunk m2 ON m1.time = m2.time\n    AND m1.device_id = 1\n    AND m2.dev"..., context = PROCESS_UTILITY_TOPLEVEL, params = 0x0, dest = 0x5603216f94d0, hypertable_list = 0x0, completion_tag = 0x7fff809b53f0, readonly_tree = false}
        altering_timescaledb = false
        result = DDL_CONTINUE
#23 0x000056031f84213a in ProcessUtility (pstmt=0x560321878b18, queryString=0x560321688e38 "EXPLAIN (costs off)\nSELECT *\nFROM _timescaledb_internal._hyper_3_13_chunk m1\n    LEFT OUTER JOIN _timescaledb_internal._hyper_3_13_chunk m2 ON m1.time = m2.time\n    AND m1.device_id = 1\n    AND m2.dev"..., readOnlyTree=false, context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0x5603216f94d0, qc=0x7fff809b53f0) at utility.c:526
No locals.
#24 0x000056031f840a3d in PortalRunUtility (portal=0x560321770a78, pstmt=0x560321878b18, isTopLevel=true, setHoldSnapshot=true, dest=0x5603216f94d0, qc=0x7fff809b53f0) at pquery.c:1158
No locals.
#25 0x000056031f84077a in FillPortalStore (portal=0x560321770a78, isTopLevel=true) at pquery.c:1031
        treceiver = 0x5603216f94d0
        qc = {commandTag = CMDTAG_UNKNOWN, nprocessed = 0}
        __func__ = "FillPortalStore"
#26 0x000056031f84002a in PortalRun (portal=0x560321770a78, count=9223372036854775807, isTopLevel=true, run_once=true, dest=0x560321847a58, altdest=0x560321847a58, qc=0x7fff809b5640) at pquery.c:763
        _save_exception_stack = 0x7fff809b5780
        _save_context_stack = 0x0
        _local_sigjmp_buf = {{__jmpbuf = {0, 1897295901112376479, 140735351054616, 94571411324917, 94571419336248, 140330535481408, 1897295901068336287, 5309095938391383199}, __mask_was_saved = 0, __saved_mask = {__val = {94571447220936, 4869, 94571445390624, 94571447220824, 112, 0, 0, 0, 472781754773333504, 140735351051632, 94571407771811, 140735351051664, 9118678122, 0, 94571447220824, 94571446340216}}}}
        _do_rethrow = false
        result = false
        nprocessed = 94571415934229
        saveTopTransactionResourceOwner = 0x560321709798
        saveTopTransactionContext = 0x5603217e10e0
        saveActivePortal = 0x0
        saveResourceOwner = 0x560321709798
        savePortalContext = 0x0
        saveMemoryContext = 0x5603217e10e0
        __func__ = "PortalRun"
#27 0x000056031f838cdc in exec_simple_query (query_string=0x560321688e38 "EXPLAIN (costs off)\nSELECT *\nFROM _timescaledb_internal._hyper_3_13_chunk m1\n    LEFT OUTER JOIN _timescaledb_internal._hyper_3_13_chunk m2 ON m1.time = m2.time\n    AND m1.device_id = 1\n    AND m2.dev"...) at postgres.c:1274
        cmdtaglen = 7
        snapshot_set = true
        per_parsetree_context = 0x0
        plantree_list = 0x560321847c08
        parsetree = 0x56032168ace8
        commandTag = CMDTAG_EXPLAIN
        qc = {commandTag = CMDTAG_UNKNOWN, nprocessed = 0}
        querytree_list = 0x560321847bd8
        portal = 0x560321770a78
        receiver = 0x560321847a58
        format = 0
        cmdtagname = 0x56031fc1882f "EXPLAIN"
        parsetree_item__state = {l = 0x560321878ae8, i = 0}
        dest = DestRemote
        oldcontext = 0x5603217e10e0
        parsetree_list = 0x560321878ae8
        parsetree_item = 0x560321878b00
        save_log_statement_stats = false
        was_logged = true
        use_implicit_block = false
        msec_str = "\200V\233\200\377\177\000\000\003~`\037\003V\000\000\000\000\000\000\000\000\000\000\060W\233\200\377\177\000"
        __func__ = "exec_simple_query"
#28 0x000056031f83de36 in PostgresMain (dbname=0x560321704058 "single", username=0x5603215f1968 "default_perm_user") at postgres.c:4637
        query_string = 0x560321688e38 "EXPLAIN (costs off)\nSELECT *\nFROM _timescaledb_internal._hyper_3_13_chunk m1\n    LEFT OUTER JOIN _timescaledb_internal._hyper_3_13_chunk m2 ON m1.time = m2.time\n    AND m1.device_id = 1\n    AND m2.dev"...
        firstchar = 81
        input_message = {data = 0x560321688e38 "EXPLAIN (costs off)\nSELECT *\nFROM _timescaledb_internal._hyper_3_13_chunk m1\n    LEFT OUTER JOIN _timescaledb_internal._hyper_3_13_chunk m2 ON m1.time = m2.time\n    AND m1.device_id = 1\n    AND m2.dev"..., len = 288, maxlen = 1024, cursor = 288}
        local_sigjmp_buf = {{__jmpbuf = {0, 1897295900655197343, 140735351054616, 94571411324917, 94571419336248, 140330535481408, 1897295901148028063, 5309095939269696671}, __mask_was_saved = 1, __saved_mask = {__val = {4194304, 140330515309856, 30464, 0, 0, 94571444763024, 94571446062600, 4869, 94571444763024, 94571446062600, 30464, 0, 94571445390624, 4294967297, 94571444763024, 140735351052384}}}}
        send_ready_for_query = false
        idle_in_transaction_timeout_enabled = false
        idle_session_timeout_enabled = false
        __func__ = "PostgresMain"
#29 0x000056031f75d699 in BackendRun (port=0x5603216f9880) at postmaster.c:4464
No locals.
#30 0x000056031f75cf15 in BackendStartup (port=0x5603216f9880) at postmaster.c:4192
        bn = 0x5603216f43e0
        pid = 0
        __func__ = "BackendStartup"
#31 0x000056031f7590f4 in ServerLoop () at postmaster.c:1782
        port = 0x5603216f9880
        i = 0
        now = 1698961678
        last_lockfile_recheck_time = 1698961673
        last_touch_time = 1698961673
        events = {{pos = 1, events = 2, fd = 7, user_data = 0x0}, {pos = 0, events = 0, fd = 0, user_data = 0x0}, {pos = 0, events = 0, fd = 0, user_data = 0x5603216fa6b0}, {pos = 2048, events = 0, fd = 0, user_data = 0x8}, {pos = 560960144, events = 22019, fd = 560965336, user_data = 0x400}, {pos = 560956008, events = 22019, fd = 1080, user_data = 0x5603216fa6e8}, {pos = 0, events = 0, fd = 0, user_data = 0x0}, {pos = 0, events = 0, fd = 560953968, user_data = 0x800}, {pos = 8, events = 0, fd = 64, user_data = 0x5603216f9290}, {pos = 560954008, events = 22019, fd = 1024, user_data = 0x5603216f9648}, {pos = 1296236546, events = 0, fd = 560965336, user_data = 0x10}, {pos = 0, events = 0, fd = 0, user_data = 0x0}, {pos = 1296236546, events = 0, fd = 560965352, user_data = 0x8}, {pos = 0, events = 0, fd = 0, user_data = 0x0}, {pos = 1296236544, events = 0, fd = 560965352, user_data = 0x8}, {pos = 0, events = 0, fd = 0, user_data = 0x0}, {pos = 1296236544, events = 0, fd = 560961080, user_data = 0x7fff809b5b90}, {pos = 530987743, events = 22019, fd = 0, user_data = 0x5603216f9290}, {pos = 1296236544, events = 0, fd = 7317208, user_data = 0x0}, {pos = 0, events = 0, fd = 560960368, user_data = 0x0}, {pos = 5120, events = 0, fd = 560961160, user_data = 0x2c0}, {pos = 3, events = 0, fd = 64, user_data = 0x56031fa5fe01 <wipe_mem+162>}, {pos = 752, events = 0, fd = 560960408, user_data = 0x0}, {pos = 0, events = 0, fd = 1296236545, user_data = 0x5603216f9398}, {pos = 752, events = 0, fd = 0, user_data = 0x0}, {pos = 0, events = 0, fd = 1296236544, user_data = 0x5603216f9398}, {pos = 752, events = 0, fd = 0, user_data = 0x0}, {pos = 0, events = 0, fd = 0, user_data = 0x68fa880458ce600}, {pos = -2137302016, events = 32767, fd = 530975298, user_data = 0x0}, {pos = 560960144, events = 22019, fd = 560965296, user_data = 0x6f9290}, {pos = 0, events = 0, fd = 560960320, user_data = 0x5603216f9290}, {pos = 1024, events = 0, fd = 88, user_data = 0x5603216f9340}, {pos = 0, events = 0, fd = 560960408, user_data = 0x7fff809b5ca0}, {pos = 531035083, events = 22019, fd = 532493742, user_data = 0x5603216f9290}, {pos = 0, events = 0, fd = 0, user_data = 0x1304}, {pos = 560960144, events = 22019, fd = 0, user_data = 0x0}, {pos = 0, events = 0, fd = 0, user_data = 0x1303}, {pos = 560960144, events = 22019, fd = 0, user_data = 0x0}, {pos = 0, events = 0, fd = 0, user_data = 0x5603216fa6e8}, {pos = 1166861824, events = 110078080, fd = -2137301776, user_data = 0x56032160e340}, {pos = 4870, events = 0, fd = 7312016, user_data = 0x5603216fa6b0}, {pos = 560960144, events = 22019, fd = 559997984, user_data = 0x0}, {pos = -128, events = 4294967295, fd = 0, user_data = 0x60b78}, {pos = 1049536317, events = 32673, fd = 1069023432, user_data = 0x7fa13fb800c8 <_rtld_global+4232>}, {pos = 1069023448, events = 32673, fd = 1069023448, user_data = 0x1304}, {pos = 1166861824, events = 110078080, fd = 0, user_data = 0xffffffffffffff80}, {pos = 0, events = 0, fd = 0, user_data = 0x56031f60bff5 <main>}, {pos = 534445624, events = 22019, fd = 1069019200, user_data = 0x7fa13e8a5453 <__GI___libc_free+115>}, {pos = 4867, events = 0, fd = 1166861824, user_data = 0x0}, {pos = -128, events = 4294967295, fd = 0, user_data = 0x7fa13e88eac1 <_IO_flush_all_lockp+481>}, {pos = -2137301520, events = 32767, fd = 530975595, user_data = 0x7fa13e88cfe0 <flush_cleanup>}, {pos = 0, events = 0, fd = 0, user_data = 0x0}, {pos = 1024, events = 0, fd = 1166861824, user_data = 0x56031fdfa570 <context_freelists+16>}, {pos = 1166861824, events = 110078080, fd = -2137301296, user_data = 0x68fa880458ce600}, {pos = -2137301296, events = 32767, fd = 1048848157, user_data = 0x56031f60bff5 <main>}, {pos = 527785003, events = 22019, fd = 4868, user_data = 0x56032160e340}, {pos = 0, events = 0, fd = 0, user_data = 0x400000}, {pos = 0, events = 0, fd = -2137301488, user_data = 0x68fa880458ce600}, {pos = -2137301376, events = 32767, fd = 560500000, user_data = 0x21701088}, {pos = 560960144, events = 22019, fd = -2137301248, user_data = 0x56031f603996 <load_ident+450>}, {pos = 1065699136, events = 32673, fd = 1050764800, user_data = 0x0}, {pos = 0, events = 2, fd = -2137301248, user_data = 0x56031f75ea00 <maybe_start_bgworkers+385>}, {pos = -2137301248, events = 32767, fd = 0, user_data = 0x0}, {pos = 560670272, events = 22019, fd = 0, user_data = 0x0}}
        nevents = 1
        __func__ = "ServerLoop"
#32 0x000056031f75899e in PostmasterMain (argc=8, argv=0x5603215ef7e0) at postmaster.c:1466
        opt = -1
        status = 0
        userDoption = 0x560321607000 "/d/github.com/fabriziomello/timescaledb/build/tsl/test/testcluster/data"
        listen_addr_saved = true
        i = 64
        output_config_variable = 0x0
        __func__ = "PostmasterMain"
#33 0x000056031f60c372 in main (argc=8, argv=0x5603215ef7e0) at main.c:198
        do_check_root = true

And checking for ht_em != NULL ...

diff --git a/tsl/src/nodes/decompress_chunk/decompress_chunk.c b/tsl/src/nodes/decompress_chunk/decompress_chunk.c
index 296409b1a..3809bc3a6 100644
--- a/tsl/src/nodes/decompress_chunk/decompress_chunk.c
+++ b/tsl/src/nodes/decompress_chunk/decompress_chunk.c
@@ -1547,16 +1547,19 @@ add_segmentby_to_equivalence_class(PlannerInfo *root, EquivalenceClass *cur_ec,
 #if PG16_GE
            EquivalenceMember *ht_em = find_em_for_relid(cur_ec, info->ht_rel->relid);
 
-           int i = -1;
-           while ((i = bms_next_member(ht_em->em_jdomain->jd_relids, i)) >= 0)
+           if (ht_em)
            {
-               RestrictInfo *d = make_simple_restrictinfo_compat(root, em->em_expr);
-               d->parent_ec = cur_ec;
-               d->left_em = find_em_for_relid(cur_ec, i);
-               if (!d->left_em)
-                   continue;
-               d->right_em = em;
-               cur_ec->ec_derives = lappend(cur_ec->ec_derives, d);
+               int i = -1;
+               while ((i = bms_next_member(ht_em->em_jdomain->jd_relids, i)) >= 0)
+               {
+                   RestrictInfo *d = make_simple_restrictinfo_compat(root, em->em_expr);
+                   d->parent_ec = cur_ec;
+                   d->left_em = find_em_for_relid(cur_ec, i);
+                   if (!d->left_em)
+                       continue;
+                   d->right_em = em;
+                   cur_ec->ec_derives = lappend(cur_ec->ec_derives, d);
+               }
            }
 #endif

... lead to another segfault:

#0  0x00007fa13e7727d6 in add_segmentby_to_equivalence_class (root=0x560321884768, cur_ec=0x560321889d78, info=0x56032185ba30, context=0x7fff809b3fd0) at /d/github.com/fabriziomello/timescaledb/tsl/src/nodes/decompress_chunk/decompress_chunk.c:1561
1561						cur_ec->ec_derives = lappend(cur_ec->ec_derives, d);
(gdb) 

Mark the EquivalenceMember for the compressed chunk as derived to
prevent an infinite recursion.
@svenklemm svenklemm merged commit c58a640 into timescale:main Nov 3, 2023
37 of 39 checks passed
@Anisimov-ds
Copy link

New changes have been made to the postgresql EquivalenceMember structure:

	/* if em_is_child is true, this links to corresponding EM for top parent */
	struct EquivalenceMember *em_parent pg_node_attr(read_write_ignore);

The code tsl/src/nodes/decompress_chunk/decompress_chunk.c below results in an inconsistent state: em->em_is_child is true, but em->em_parent is NULL.

		/* copied from add_eq_member */
		{
			EquivalenceMember *em = makeNode(EquivalenceMember);

			em->em_expr = child_expr;
			em->em_relids = new_relids;
			em->em_is_const = false;
			em->em_is_child = true;
			em->em_datatype = cur_em->em_datatype;

Could this cause errors such as infinite recursion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pg16 Issue/PR related to support for PG16
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants