Open ycybfhb opened 1 week ago
Thank you for reporting @ycybfhb , I was able to reproduce on 2.21.1.0.
Just download the files: init.sql: init.sql.txt error.sql: error.sql.txt
And run:
./bin/ysqlsh -h 127.0.1.1 -d test0 -f init.sql.txt
./bin/ysqlsh -h 127.0.1.1 -d test0 -f error.sql.txt
ysqlsh:error.sql.txt:79: ERROR: tupdesc reference 0x48c7d9f2038 is not owned by resource owner Portal
Thank you for reporting this issue @ycybfhb.
Here's a minimal example that reproduces the issue on latest master:
-- Setup
CREATE TABLE mock (i INT PRIMARY KEY);
-- Query
INSERT INTO mock VALUES (case when (pg_catalog.boollt(true::boolean, EXISTS(select 1)) in (select true)) then 10 else -10 end), (15);
The EXPLAIN plan produced by the query:
QUERY PLAN
-------------------------------------------------------------------
Insert on mock (cost=0.01..0.04 rows=2 width=4)
InitPlan 1 (returns $0)
-> Result (cost=0.00..0.01 rows=1 width=0)
-> Values Scan on "*VALUES*" (cost=0.00..0.03 rows=2 width=4)
(4 rows)
Stacktrace (line numbers may be invalid):
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x7f7f7f7f7f7f7f7f)
* frame #0: 0x0000000102f9be30 postgres`castNodeImpl(type=T_TupleTableSlot, ptr=0x7f7f7f7f7f7f7f7f) at nodes.h:609:2
frame #1: 0x0000000102f9bca4 postgres`ExecResetTupleTable(tupleTable=0x00000001040aed30, shouldFree=false) at execTuples.c:200:26
frame #2: 0x0000000102f895a4 postgres`ExecEndPlan(planstate=0x0000000115373000, estate=0x00000001040ae120) at execMain.c:1646:2
frame #3: 0x0000000102f894c8 postgres`standard_ExecutorEnd(queryDesc=0x000000010b7f2d20) at execMain.c:495:2
frame #4: 0x0000000103deea54 pg_stat_statements.so`pgss_ExecutorEnd(queryDesc=0x000000010b7f2d20) at pg_stat_statements.c:1388:3
frame #5: 0x0000000103e366fc yb_pg_metrics.so`ybpgm_ExecutorEnd(queryDesc=0x000000010b7f2d20) at yb_pg_metrics.c:693:7
RCA: This was an issue with lifecycle management of TupleTableSlots used in SubPlans (CASE WHEN(..) ... END
) that were used in conjunction with a ValueScan (inserting multiple rows). The issue was present in vanilla postgres 11.2 (the version YugabyteDB is currently based on) and fixed in a subsequent minor release of postgres 11.
I have imported and tested the fix in YugabyteDB. The fix will be made available in all currently-supported releases of YugabyteDB.
Thank you again for reporting the issue!
Jira Link: DB-11885
Description
Basic Information
Version:
Deploy:
Reproduce
Firstly, connect to the database via the
psql
command.Secondly, execute the statements in
init.sql
to create the tables.Finally, when executing the statements in
error.sql
, a crash occurred, and the server closed the connection.init.sql: init.sql.txt error.sql: error.sql.txt
Error Log
postgresql-2024-06-21_084101.log
About Us
We are the BASS team from the School of Cyber Science and Technology at Beihang University. Our main focus is on system software security, operating systems, and program analysis research, as well as the development of automated program testing frameworks for detecting software defects. Using our self-developed database vulnerability testing tool, we have identified the above-mentioned vulnerabilities in Yugabyte that may lead to database crashes.
Issue Type
kind/bug
Warning: Please confirm that this issue does not contain any sensitive information