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

[YSQL][randgen] Query with correlated aggregate subquery crashes in pg_detoast_datum_packed (EXC_BAD_ACCESS) #21004

Closed
1 task done
mtakahar opened this issue Feb 9, 2024 · 0 comments
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/highest Highest priority issue

Comments

@mtakahar
Copy link
Contributor

mtakahar commented Feb 9, 2024

Jira Link: DB-9977

Description

Problem

  • Found by RQG during a porting attempt of optimizer_subquery_portable.yy).
  • Crashes on the latest master (0214819), both release and debug build.
  • EXPLAIN command crashes, too.

Test Case

(Manually simplified)

DROP TABLE /*! IF EXISTS */ BB;

CREATE TABLE BB (
	col_varchar_key VARCHAR(1) /*! NULL */,
	col_varchar_nokey VARCHAR(1) /*! NULL */);

CREATE INDEX BB_varchar_key ON BB(col_varchar_key ASC);

INSERT /*! IGNORE */ INTO BB (
	col_varchar_key, col_varchar_nokey
) VALUES ('g', 'g');
psql (15.1, server 11.2-YB-2.21.1.0-b0)
You are now connected to database "test" as user "yugabyte".
test=# EXPLAIN SELECT
   ( SELECT COUNT(*) FROM BB AS SUBQUERY1_t1 WHERE SUBQUERY1_t1.col_varchar_key <= table1.col_varchar_nokey AND SUBQUERY1_t1.col_varchar_key <= table1.col_varchar_nokey) AS field1
FROM BB AS table1;

server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.
psql (15.1, server 11.2-YB-2.21.1.0-b0)
test=# 
test=# \c
psql (15.1, server 11.2-YB-2.21.1.0-b0)
You are now connected to database "test" as user "yugabyte".
test=# EXPLAIN SELECT
   ( SELECT COUNT(*) FROM BB AS SUBQUERY1_t1 WHERE SUBQUERY1_t1.col_varchar_key <= table1.col_varchar_nokey AND SUBQUERY1_t1.col_varchar_key <= table1.col_varchar_nokey) AS field1
FROM BB AS table1;

server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.
psql (15.1, server 11.2-YB-2.21.1.0-b0)
test=# 

Backtrace (EXPLAIN):

(lldb) Process 71750 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000108dd49b0 postgres`pg_detoast_datum_packed + 16 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/utils/fmgr/fmgr.c:2019
   2016	struct varlena *
   2017	pg_detoast_datum_packed(struct varlena *datum)
   2018	{
-> 2019		if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
    		    ^
   2020			return heap_tuple_untoast_attr(datum);
   2021		else
   2022			return datum;
Target 0: (postgres) stopped.
(lldb)  bt
bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x0000000108dd49b0 postgres`pg_detoast_datum_packed + 16 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/utils/fmgr/fmgr.c:2019
    frame #1: 0x0000000108d71ae9 postgres`text_le + 25 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/utils/adt/varlena.c:1722
    frame #2: 0x0000000108dd2018 postgres`FunctionCall2Coll + 168 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/utils/fmgr/fmgr.c:1190
    frame #3: 0x00000001086bb8d4 postgres`YbBindScanKeys + 2932 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/access/yb_access/yb_scan.c:1949
    frame #4: 0x00000001086ba620 postgres`YbPredetermineNeedsRecheck + 208 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/access/yb_access/yb_scan.c:2060
    frame #5: 0x00000001086cd13c postgres`ybcinmightrecheck + 60 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/access/yb_access/yb_lsm.c:310
    frame #6: 0x0000000108622dbd postgres`yb_index_might_recheck + 429 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/access/index/indexam.c:984
    frame #7: 0x0000000108951854 postgres`ExecInitIndexOnlyScan + 740 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/executor/nodeIndexonlyscan.c:694
    frame #8: 0x000000010892439f postgres`ExecInitNode + 1071 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/executor/execProcnode.c:230
    frame #9: 0x00000001089342fa postgres`ExecInitAgg + 1450 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/executor/nodeAgg.c:2606
    frame #10: 0x0000000108924593 postgres`ExecInitNode + 1571 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/executor/execProcnode.c:337
    frame #11: 0x00000001089174a5 postgres`InitPlan + 1973 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/executor/execMain.c:1034
    frame #12: 0x0000000108916b5c postgres`standard_ExecutorStart + 780 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/executor/execMain.c:255
    frame #13: 0x000000010cfb0f9e pg_stat_statements.so`pgss_ExecutorStart + 62 at /Users/mtakahara/code/yugabyte-db2/src/postgres/contrib/pg_stat_statements/pg_stat_statements.c:1273
    frame #14: 0x000000010cfcc40d yb_pg_metrics.so`ybpgm_ExecutorStart + 45 at /Users/mtakahara/code/yugabyte-db2/src/postgres/contrib/yb_pg_metrics/yb_pg_metrics.c:557
    frame #15: 0x000000010d304bdd pgaudit.so`pgaudit_NextExecutorStart_hook + 45 at /Users/mtakahara/code/yugabyte-db2/src/postgres/contrib/pgaudit/pgaudit.c:1084
    frame #16: 0x000000010d304245 pgaudit.so`pgaudit_ExecutorStart_hook + 53 at /Users/mtakahara/code/yugabyte-db2/src/postgres/contrib/pgaudit/pgaudit.c:1101
    frame #17: 0x000000010891682d postgres`ExecutorStart + 45 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/executor/execMain.c:136
    frame #18: 0x000000010881d985 postgres`ExplainOnePlan + 437 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/commands/explain.c:1270
    frame #19: 0x000000010881d194 postgres`ExplainOneQuery + 308 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/commands/explain.c:1119
    frame #20: 0x000000010881cc14 postgres`ExplainQuery + 3012 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/commands/explain.c:998
    frame #21: 0x0000000108bc2799 postgres`standard_ProcessUtility + 2153 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/utility.c:702
    frame #22: 0x0000000108bc1972 postgres`YBProcessUtilityDefaultHook + 226 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/utility.c:3615
    frame #23: 0x000000010cfb1575 pg_stat_statements.so`pgss_ProcessUtility + 389 at /Users/mtakahara/code/yugabyte-db2/src/postgres/contrib/pg_stat_statements/pg_stat_statements.c:1420
    frame #24: 0x000000010cfccbc5 yb_pg_metrics.so`ybpgm_ProcessUtility + 389 at /Users/mtakahara/code/yugabyte-db2/src/postgres/contrib/yb_pg_metrics/yb_pg_metrics.c:772
    frame #25: 0x000000010d3058a9 pgaudit.so`pgaudit_NextProcessUtility_hook + 89 at /Users/mtakahara/code/yugabyte-db2/src/postgres/contrib/pgaudit/pgaudit.c:1192
    frame #26: 0x000000010d304537 pgaudit.so`pgaudit_ProcessUtility_hook + 151 at /Users/mtakahara/code/yugabyte-db2/src/postgres/contrib/pgaudit/pgaudit.c:1220
    frame #27: 0x00000001104ee429 pg_hint_plan.so`pg_hint_plan_ProcessUtility + 89 at /Users/mtakahara/code/yugabyte-db2/src/postgres/third-party-extensions/pg_hint_plan/pg_hint_plan.c:3056
    frame #28: 0x0000000108e183d6 postgres`YBTxnDdlProcessUtility + 294 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/utils/misc/pg_yb_utils.c:2099
    frame #29: 0x0000000108bc1ef8 postgres`ProcessUtility + 248 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/utility.c:377
    frame #30: 0x0000000108bc14fe postgres`PortalRunUtility + 350 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/pquery.c:1206
    frame #31: 0x0000000108bbfed8 postgres`FillPortalStore + 248 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/pquery.c:1066
    frame #32: 0x0000000108bbfa05 postgres`PortalRun + 773 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/pquery.c:784
    frame #33: 0x0000000108bbce6a postgres`exec_simple_query + 1546 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/postgres.c:1220
    frame #34: 0x0000000108bba985 postgres`yb_exec_simple_query_impl + 21 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/postgres.c:4738
    frame #35: 0x0000000108bbaaea postgres`yb_exec_query_wrapper_one_attempt + 346 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/postgres.c:4706
    frame #36: 0x0000000108bba95a postgres`yb_exec_query_wrapper + 74 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/postgres.c:4730
    frame #37: 0x0000000108bb5c45 postgres`yb_exec_simple_query + 69 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/postgres.c:4753
    frame #38: 0x0000000108bb455e postgres`PostgresMain + 2910 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/postgres.c:5378
    frame #39: 0x0000000108ad3505 postgres`BackendRun + 933 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/postmaster/postmaster.c:4736
    frame #40: 0x0000000108ad25af postgres`BackendStartup + 703 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/postmaster/postmaster.c:4400
    frame #41: 0x0000000108ad0f60 postgres`ServerLoop + 992 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/postmaster/postmaster.c:1778
    frame #42: 0x0000000108acd4f2 postgres`PostmasterMain + 7570 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/postmaster/postmaster.c:1434
    frame #43: 0x00000001089bf0ab postgres`PostgresServerProcessMain + 779 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/main/main.c:234
    frame #44: 0x00000001089bf662 postgres`main + 34
    frame #45: 0x00007ff8061ca41f dyld`start + 1903
(lldb)

Backtrace (No EXPLAIN):

(lldb) Process 71823 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000108dd49b0 postgres`pg_detoast_datum_packed + 16 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/utils/fmgr/fmgr.c:2019
   2016	struct varlena *
   2017	pg_detoast_datum_packed(struct varlena *datum)
   2018	{
-> 2019		if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
    		    ^
   2020			return heap_tuple_untoast_attr(datum);
   2021		else
   2022			return datum;
Target 0: (postgres) stopped.
(lldb)  p datum
p datum
(varlena *) NULL
(lldb) bt
bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x0000000108dd49b0 postgres`pg_detoast_datum_packed + 16 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/utils/fmgr/fmgr.c:2019
    frame #1: 0x0000000108d71ae9 postgres`text_le + 25 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/utils/adt/varlena.c:1722
    frame #2: 0x0000000108dd2018 postgres`FunctionCall2Coll + 168 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/utils/fmgr/fmgr.c:1190
    frame #3: 0x00000001086bb8d4 postgres`YbBindScanKeys + 2932 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/access/yb_access/yb_scan.c:1949
    frame #4: 0x00000001086ba620 postgres`YbPredetermineNeedsRecheck + 208 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/access/yb_access/yb_scan.c:2060
    frame #5: 0x00000001086cd13c postgres`ybcinmightrecheck + 60 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/access/yb_access/yb_lsm.c:310
    frame #6: 0x0000000108622dbd postgres`yb_index_might_recheck + 429 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/access/index/indexam.c:984
    frame #7: 0x0000000108951854 postgres`ExecInitIndexOnlyScan + 740 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/executor/nodeIndexonlyscan.c:694
    frame #8: 0x000000010892439f postgres`ExecInitNode + 1071 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/executor/execProcnode.c:230
    frame #9: 0x00000001089342fa postgres`ExecInitAgg + 1450 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/executor/nodeAgg.c:2606
    frame #10: 0x0000000108924593 postgres`ExecInitNode + 1571 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/executor/execProcnode.c:337
    frame #11: 0x00000001089174a5 postgres`InitPlan + 1973 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/executor/execMain.c:1034
    frame #12: 0x0000000108916b5c postgres`standard_ExecutorStart + 780 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/executor/execMain.c:255
    frame #13: 0x000000010cfb0f9e pg_stat_statements.so`pgss_ExecutorStart + 62 at /Users/mtakahara/code/yugabyte-db2/src/postgres/contrib/pg_stat_statements/pg_stat_statements.c:1273
    frame #14: 0x000000010cfcc40d yb_pg_metrics.so`ybpgm_ExecutorStart + 45 at /Users/mtakahara/code/yugabyte-db2/src/postgres/contrib/yb_pg_metrics/yb_pg_metrics.c:557
    frame #15: 0x000000010d304bdd pgaudit.so`pgaudit_NextExecutorStart_hook + 45 at /Users/mtakahara/code/yugabyte-db2/src/postgres/contrib/pgaudit/pgaudit.c:1084
    frame #16: 0x000000010d304245 pgaudit.so`pgaudit_ExecutorStart_hook + 53 at /Users/mtakahara/code/yugabyte-db2/src/postgres/contrib/pgaudit/pgaudit.c:1101
    frame #17: 0x000000010891682d postgres`ExecutorStart + 45 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/executor/execMain.c:136
    frame #18: 0x0000000108bbf1a5 postgres`PortalStart + 709 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/pquery.c:536
    frame #19: 0x0000000108bbcd56 postgres`exec_simple_query + 1270 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/postgres.c:1181
    frame #20: 0x0000000108bba985 postgres`yb_exec_simple_query_impl + 21 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/postgres.c:4738
    frame #21: 0x0000000108bbaaea postgres`yb_exec_query_wrapper_one_attempt + 346 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/postgres.c:4706
    frame #22: 0x0000000108bba95a postgres`yb_exec_query_wrapper + 74 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/postgres.c:4730
    frame #23: 0x0000000108bb5c45 postgres`yb_exec_simple_query + 69 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/postgres.c:4753
    frame #24: 0x0000000108bb455e postgres`PostgresMain + 2910 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/tcop/postgres.c:5378
    frame #25: 0x0000000108ad3505 postgres`BackendRun + 933 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/postmaster/postmaster.c:4736
    frame #26: 0x0000000108ad25af postgres`BackendStartup + 703 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/postmaster/postmaster.c:4400
    frame #27: 0x0000000108ad0f60 postgres`ServerLoop + 992 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/postmaster/postmaster.c:1778
    frame #28: 0x0000000108acd4f2 postgres`PostmasterMain + 7570 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/postmaster/postmaster.c:1434
    frame #29: 0x00000001089bf0ab postgres`PostgresServerProcessMain + 779 at /Users/mtakahara/code/yugabyte-db2/src/postgres/src/backend/main/main.c:234
    frame #30: 0x00000001089bf662 postgres`main + 34
    frame #31: 0x00007ff8061ca41f dyld`start + 1903
(lldb)

Issue Type

kind/bug

Warning: Please confirm that this issue does not contain any sensitive information

  • I confirm this issue does not contain any sensitive information.
@mtakahar mtakahar added area/ysql Yugabyte SQL (YSQL) status/awaiting-triage Issue awaiting triage labels Feb 9, 2024
@yugabyte-ci yugabyte-ci added kind/bug This issue is a bug priority/medium Medium priority issue labels Feb 9, 2024
@sushantrmishra sushantrmishra removed status/awaiting-triage Issue awaiting triage priority/medium Medium priority issue labels Feb 9, 2024
@yugabyte-ci yugabyte-ci added priority/medium Medium priority issue priority/highest Highest priority issue and removed priority/medium Medium priority issue labels Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/highest Highest priority issue
Projects
None yet
Development

No branches or pull requests

4 participants