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] Segmentation fault on return ROW from FUNCTION #1676

Closed
d-uspenskiy opened this issue Jul 2, 2019 · 3 comments
Closed

[YSQL] Segmentation fault on return ROW from FUNCTION #1676

d-uspenskiy opened this issue Jul 2, 2019 · 3 comments
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug
Projects

Comments

@d-uspenskiy
Copy link
Contributor

d-uspenskiy commented Jul 2, 2019

The following sequence of commands causes Segmentation fault in postgresql process

postgres=# create or replace function composrec() returns record as $$
postgres$# declare
postgres$#   v record;
postgres$# begin
postgres$#   v := (1, 'hello');
postgres$#   return v;
postgres$# end;
postgres$# $$ language plpgsql;

postgres=# select composrec();
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: Failed.

Also SELECT from TEMP table causes Segmentation fault

postgres=# create temp table foo (f1 int, f2 int);

postgres=# insert into foo values (1,2), (3,4);

postgres=# create or replace function stricttest() returns void as $$
declare x record;
begin
  -- should work
  select * from foo where f1 = 3 into strict x;
  raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2;
end$$ language plpgsql;
CREATE FUNCTION

postgres=# select stricttest();
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: Failed.
!> 
@d-uspenskiy d-uspenskiy added area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug labels Jul 2, 2019
@d-uspenskiy d-uspenskiy added this to To do in YSQL via automation Jul 2, 2019
@d-uspenskiy d-uspenskiy changed the title Segmentation fault on SELECT from TEMP table inside function Segmentation fault on return ROW from FUNCTION Jul 2, 2019
@d-uspenskiy d-uspenskiy changed the title Segmentation fault on return ROW from FUNCTION [YSQL] Segmentation fault on return ROW from FUNCTION Jul 2, 2019
@kmuthukk
Copy link
Collaborator

kmuthukk commented Jul 2, 2019

Stack trace for:

select composrec();

(gdb) where
#0  __memcpy_avx_unaligned () at ../sysdeps/x86_64/multiarch/memcpy-avx-unaligned.S:238
#1  0x00000000008fb2e5 in cstring_to_text_with_len (s=0x7ffdf8f7b764 "", len=3629796) at ../../../../../../../src/postgres/src/backend/utils/adt/varlena.c:166
#2  0x000000000049f716 in heap_copytuple (tuple=tuple@entry=0x7ffdf8f7b710) at ../../../../../../../src/postgres/src/backend/access/common/heaptuple.c:741
#3  0x0000000000826f91 in expanded_record_set_tuple (erh=0x231ff20, tuple=0x7ffdf8f7b710, copy=<optimized out>, expand_external=false) at ../../../../../../../src/postgres/src/backend/utils/ad\
t/expandedrecord.c:493
#4  0x00007f3120035c77 in exec_move_row_from_datum (estate=estate@entry=0x7ffdf8f7bc30, target=target@entry=0x22223a8, value=value@entry=36758280) at ../../../../../../../src/postgres/src/pl/p\
lpgsql/src/pl_exec.c:7368
#5  0x00007f3120033cbb in exec_assign_value (estate=0x7ffdf8f7bc30, target=0x22223a8, value=36758280, isNull=false, valtype=2249, valtypmod=-1) at ../../../../../../../src/postgres/src/pl/plpg\
sql/src/pl_exec.c:5006
#6  0x00007f3120035fce in exec_assign_expr (estate=0x7ffdf8f7bc30, target=0x22223a8, expr=0x205b778) at ../../../../../../../src/postgres/src/pl/plpgsql/src/pl_exec.c:4859
#7  0x00007f3120037de8 in exec_stmt_assign (stmt=0x203acd8, stmt=0x203acd8, estate=0x7ffdf8f7bc30) at ../../../../../../../src/postgres/src/pl/plpgsql/src/pl_exec.c:2046
#8  exec_stmt (stmt=0x203acd8, estate=0x7ffdf8f7bc30) at ../../../../../../../src/postgres/src/pl/plpgsql/src/pl_exec.c:1914
#9  exec_stmts (estate=0x7ffdf8f7bc30, stmts=<optimized out>) at ../../../../../../../src/postgres/src/pl/plpgsql/src/pl_exec.c:1877
#10 0x00007f312003b1cc in exec_stmt_block (estate=estate@entry=0x7ffdf8f7bc30, block=0x203add8) at ../../../../../../../src/postgres/src/pl/plpgsql/src/pl_exec.c:1818
#11 0x00007f312003b632 in plpgsql_exec_function (func=func@entry=0x1f12d78, fcinfo=fcinfo@entry=0x1f826b0, simple_eval_estate=simple_eval_estate@entry=0x0, atomic=atomic@entry=true) at ../../.\
./../../../../src/postgres/src/pl/plpgsql/src/pl_exec.c:587
#12 0x00007f312002b97a in plpgsql_call_handler (fcinfo=0x1f826b0) at ../../../../../../../src/postgres/src/pl/plpgsql/src/pl_handler.c:263
#13 0x000000000065b233 in ExecInterpExpr (state=0x1f825d8, econtext=0x1f82300, isnull=<optimized out>) at ../../../../../../src/postgres/src/backend/executor/execExprInterp.c:1189
#14 0x0000000000688ca6 in ExecEvalExprSwitchContext (isNull=0x7ffdf8f7bf0f, econtext=0x1f82300, state=0x1f825d8) at ../../../../../../src/postgres/src/include/executor/executor.h:313
#15 ExecProject (projInfo=0x1f825d0) at ../../../../../../src/postgres/src/include/executor/executor.h:347
#16 ExecResult (pstate=<optimized out>) at ../../../../../../src/postgres/src/backend/executor/nodeResult.c:136
#17 0x000000000065f3cb in ExecProcNode (node=0x1f821f0) at ../../../../../../src/postgres/src/include/executor/executor.h:247
#18 ExecutePlan (execute_once=<optimized out>, dest=0x27b6e18, direction=<optimized out>, numberTuples=0, sendTuples=<optimized out>, operation=CMD_SELECT, use_parallel_mode=<optimized out>, p\
lanstate=0x1f821f0, estate=0x1f81fe0)
    at ../../../../../../src/postgres/src/backend/executor/execMain.c:1729
#19 standard_ExecutorRun (queryDesc=0x1f063e0, direction=<optimized out>, count=0, execute_once=<optimized out>) at ../../../../../../src/postgres/src/backend/executor/execMain.c:365
#20 0x00007f31322c562d in ybpgm_ExecutorRun (queryDesc=0x1f063e0, direction=ForwardScanDirection, count=0, execute_once=<optimized out>) at ../../../../../src/postgres/contrib/yb_pg_metrics/yb\
_pg_metrics.c:390
#21 0x00000000007e0b7b in PortalRunSelect (portal=portal@entry=0x1f4b0e0, forward=forward@entry=true, count=0, count@entry=9223372036854775807, dest=dest@entry=0x27b6e18) at ../../../../../../\
src/postgres/src/backend/tcop/pquery.c:939
#22 0x00000000007e2239 in PortalRun (portal=portal@entry=0x1f4b0e0, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, run_once=run_once@entry=true, dest=dest@entry=0x27b\
6e18, altdest=altdest@entry=0x27b6e18, completionTag=0x7ffdf8f7c2d0 "")
    at ../../../../../../src/postgres/src/backend/tcop/pquery.c:780
#23 0x00000000007ddf5c in exec_simple_query (query_string=0x1eda190 "select composrec();") at ../../../../../../src/postgres/src/backend/tcop/postgres.c:1149
#24 0x00000000007df1ac in PostgresMain (argc=<optimized out>, argv=argv@entry=0x1f11718, dbname=0x1f115f8 "postgres", username=0x1f115d8 "postgres") at ../../../../../../src/postgres/src/backe\
nd/tcop/postgres.c:4373
#25 0x00000000004927ad in BackendRun (port=0x1f07c20) at ../../../../../../src/postgres/src/backend/postmaster/postmaster.c:4398
#26 BackendStartup (port=0x1f07c20) at ../../../../../../src/postgres/src/backend/postmaster/postmaster.c:4064
#27 ServerLoop () at ../../../../../../src/postgres/src/backend/postmaster/postmaster.c:1724
#28 0x0000000000759a68 in PostmasterMain (argc=argc@entry=19, argv=argv@entry=0x1efa330) at ../../../../../../src/postgres/src/backend/postmaster/postmaster.c:1387
#29 0x00000000006b229a in PostgresServerProcessMain (argc=19, argv=0x1efa330) at ../../../../../../src/postgres/src/backend/main/main.c:234
#30 0x00000000006b2499 in main ()

@kmuthukk
Copy link
Collaborator

kmuthukk commented Jul 2, 2019

Slightly different stack for the 2nd issue (temptable) issue reported above.

(gdb) where
#0  0x000000000049f6f0 in heap_copytuple (tuple=0x26c1ce8) at ../../../../../../../src/postgres/src/backend/access/common/heaptuple.c:741
#1  0x000000000066a81f in ExecCopySlotTuple (slot=slot@entry=0x26c0fb0) at ../../../../../../src/postgres/src/backend/executor/execTuples.c:593
#2  0x0000000000698ecf in spi_printtup (slot=0x26c0fb0, self=<optimized out>) at ../../../../../../src/postgres/src/backend/executor/spi.c:1860
#3  0x000000000065f444 in ExecutePlan (execute_once=<optimized out>, dest=0xdcce80 <spi_printtupDR>, direction=<optimized out>, numberTuples=2, sendTuples=<optimized out>, operation=CMD_SELECT\
, use_parallel_mode=<optimized out>, planstate=0x26c0dc0, estate=0x26c0bb0)
    at ../../../../../../src/postgres/src/backend/executor/execMain.c:1768
#4  standard_ExecutorRun (queryDesc=0x24a3cc8, direction=<optimized out>, count=2, execute_once=<optimized out>) at ../../../../../../src/postgres/src/backend/executor/execMain.c:365
#5  0x00007f31322c562d in ybpgm_ExecutorRun (queryDesc=0x24a3cc8, direction=ForwardScanDirection, count=2, execute_once=<optimized out>) at ../../../../../src/postgres/contrib/yb_pg_metrics/yb\
_pg_metrics.c:390
#6  0x0000000000696f5c in _SPI_pquery (tcount=2, fire_triggers=true, queryDesc=0x24a3cc8) at ../../../../../../src/postgres/src/backend/executor/spi.c:2484
#7  _SPI_execute_plan (plan=plan@entry=0x241e410, paramLI=paramLI@entry=0x0, snapshot=snapshot@entry=0x0, crosscheck_snapshot=crosscheck_snapshot@entry=0x0, read_only=read_only@entry=false, fi\
re_triggers=fire_triggers@entry=true, tcount=2)
    at ../../../../../../src/postgres/src/backend/executor/spi.c:2246
#8  0x00000000006974ec in SPI_execute_plan_with_paramlist (plan=0x241e410, params=0x0, read_only=<optimized out>, tcount=2) at ../../../../../../src/postgres/src/backend/executor/spi.c:523
#9  0x00007f3107ce766d in exec_stmt_execsql (estate=estate@entry=0x7ffdf8f7bc30, stmt=stmt@entry=0x22ffc98) at ../../../../../../../src/postgres/src/pl/plpgsql/src/pl_exec.c:4115
#10 0x00007f3107cea86b in exec_stmt (stmt=0x22ffc98, estate=0x7ffdf8f7bc30) at ../../../../../../../src/postgres/src/pl/plpgsql/src/pl_exec.c:1986
#11 exec_stmts (estate=0x7ffdf8f7bc30, stmts=<optimized out>) at ../../../../../../../src/postgres/src/pl/plpgsql/src/pl_exec.c:1877
#12 0x00007f3107ced1cc in exec_stmt_block (estate=estate@entry=0x7ffdf8f7bc30, block=0x2300248) at ../../../../../../../src/postgres/src/pl/plpgsql/src/pl_exec.c:1818
#13 0x00007f3107ced632 in plpgsql_exec_function (func=func@entry=0x1f14830, fcinfo=fcinfo@entry=0x236b500, simple_eval_estate=simple_eval_estate@entry=0x0, atomic=atomic@entry=true) at ../../.\
./../../../../src/postgres/src/pl/plpgsql/src/pl_exec.c:587
#14 0x00007f3107cdd97a in plpgsql_call_handler (fcinfo=0x236b500) at ../../../../../../../src/postgres/src/pl/plpgsql/src/pl_handler.c:263
#15 0x000000000065b233 in ExecInterpExpr (state=0x236b428, econtext=0x236b150, isnull=<optimized out>) at ../../../../../../src/postgres/src/backend/executor/execExprInterp.c:1189
#16 0x0000000000688ca6 in ExecEvalExprSwitchContext (isNull=0x7ffdf8f7bf0f, econtext=0x236b150, state=0x236b428) at ../../../../../../src/postgres/src/include/executor/executor.h:313
#17 ExecProject (projInfo=0x236b420) at ../../../../../../src/postgres/src/include/executor/executor.h:347
#18 ExecResult (pstate=<optimized out>) at ../../../../../../src/postgres/src/backend/executor/nodeResult.c:136
#19 0x000000000065f3cb in ExecProcNode (node=0x236b040) at ../../../../../../src/postgres/src/include/executor/executor.h:247
#20 ExecutePlan (execute_once=<optimized out>, dest=0x21f2488, direction=<optimized out>, numberTuples=0, sendTuples=<optimized out>, operation=CMD_SELECT, use_parallel_mode=<optimized out>, p\
lanstate=0x236b040, estate=0x236ae30)
    at ../../../../../../src/postgres/src/backend/executor/execMain.c:1729
#21 standard_ExecutorRun (queryDesc=0x1f063e0, direction=<optimized out>, count=0, execute_once=<optimized out>) at ../../../../../../src/postgres/src/backend/executor/execMain.c:365
#22 0x00007f31322c562d in ybpgm_ExecutorRun (queryDesc=0x1f063e0, direction=ForwardScanDirection, count=0, execute_once=<optimized out>) at ../../../../../src/postgres/contrib/yb_pg_metrics/yb\
_pg_metrics.c:390
#23 0x00000000007e0b7b in PortalRunSelect (portal=portal@entry=0x1f490e0, forward=forward@entry=true, count=0, count@entry=9223372036854775807, dest=dest@entry=0x21f2488) at ../../../../../../\
src/postgres/src/backend/tcop/pquery.c:939
#24 0x00000000007e2239 in PortalRun (portal=portal@entry=0x1f490e0, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, run_once=run_once@entry=true, dest=dest@entry=0x21f\
2488, altdest=altdest@entry=0x21f2488, completionTag=0x7ffdf8f7c2d0 "")
    at ../../../../../../src/postgres/src/backend/tcop/pquery.c:780
#25 0x00000000007ddf5c in exec_simple_query (query_string=0x1eda190 "select stricttest();") at ../../../../../../src/postgres/src/backend/tcop/postgres.c:1149
#26 0x00000000007df1ac in PostgresMain (argc=<optimized out>, argv=argv@entry=0x1f09ee8, dbname=0x1f09d98 "postgres", username=0x1f09d78 "postgres") at ../../../../../../src/postgres/src/backe\
nd/tcop/postgres.c:4373
#27 0x00000000004927ad in BackendRun (port=0x1f05340) at ../../../../../../src/postgres/src/backend/postmaster/postmaster.c:4398
#28 BackendStartup (port=0x1f05340) at ../../../../../../src/postgres/src/backend/postmaster/postmaster.c:4064
#29 ServerLoop () at ../../../../../../src/postgres/src/backend/postmaster/postmaster.c:1724
#30 0x0000000000759a68 in PostmasterMain (argc=argc@entry=19, argv=argv@entry=0x1efa330) at ../../../../../../src/postgres/src/backend/postmaster/postmaster.c:1387
#31 0x00000000006b229a in PostgresServerProcessMain (argc=19, argv=0x1efa330) at ../../../../../../src/postgres/src/backend/main/main.c:234
#32 0x00000000006b2499 in main ()

@jaki
Copy link
Contributor

jaki commented Jul 29, 2019

This will may be fixed with issue #1152.

@jaki jaki assigned jaki and unassigned mbautin Aug 1, 2019
@jaki jaki moved this from To do to In progress in YSQL Aug 6, 2019
jaki pushed a commit to jaki/yugabyte-db that referenced this issue Aug 22, 2019
Fix another issue around records where a heap tuple does not set its
`t_ybctid` invalid.  Resolve the yugabyte#1676 TODOs, mainly involving
uncommenting `SELECT` statements.  Fix some whitespace diff issues.  The
`yb_plpgsql` test should continue to pass.
jaki pushed a commit that referenced this issue Aug 26, 2019
Summary:
Enable `CREATE TYPE` and `DROP TYPE` for user-defined types, closing
issue #1152.  This includes user-defined composite types, enum types,
range types, base types, and shell types.  Also extend support to record
types, particularly those returning from functions, and close issues
#742 and #1676.

* Defer `ALTER TYPE` to issue #1893
* Map Postgres user-defined types either to existing Postgres base types
  or directly to Yugabyte types
* Apply fixes related to issue #1156 in regress test `yb_pg_plpgsql`
  (formerly named `yb_plpgsql`)
* Invalidate some `t_ybctid` attributes of `HeapTuple`s to get records
  working
* Discover and create a potentially related issue #1975
* Update several Postgres regress tests
* Create new Postgres regress tests
* Rename related tests from `yb_foo` to `yb_pg_foo` if they are
  derivatives of the vanilla Postgres `foo` test
* Port related tests from `foo` to `yb_pg_foo` by copying then modifying
* Fix an issue with the expected output of `TestPgDump` that is **not**
  related to UDTs and records

Assuming it still exists, see fine-grained commit history at
jj-kim/yugabyte-db/tree/support-user-defined-type.  Otherwise, here are
the commit message subjects (most recent to least recent).

* Comment out more of an unrelated issue
* Add more DISCARD TEMP just in case
* Add DISCARD TEMP to the end of some tests
* Set UDT type entity OIDs to invalid
* Combine some DROP TABLE statements
* Fix yb_pg_foreign_key expected output from 0294a9c
* Rename schedule collections to arrays
* Add yb_pg_rowtypes regress test
* Order tests in schedules; split yb_create_index
* Dynamically create type entities for certain UDTs
* Improve base type test with custom C func type
* Add base type test and handle more base type cases
* Increase fixed length type entity size to 8 bytes
* Reduce large diffs for yb_pg_jsonb test
* Add testjsonb table for yb_pg_jsonb test
* Reduce diff for yb_pg_jsonb Postgres regress tests
* Rename more Postgres regress tests
* Port case regress test to yb_pg_case
* Add missing feature tests to yb_feature_types
* Fix TestPgDump expected output discrepancy
* Uncomment/fix more statements in yb_arrays test
* Fix TestPgRegressBetaFeatures java test from tenk1
* Fix TestPgRegressPgMisc java test due to tenk1
* Remove WITH OIDS when creating tenk1 table
* Finish cleaning off yb_privileges test
* Resolve part of yb_privileges regress test
* Remap UDTs without mucking around sys attributes
* Increase timeout of TestPgRegressLargeTable
* Uncomment TODOs in yb_arrays test
* Remove TestPgTypes java test
* Uncomment more statements in yb_pg_json test
* Uncomment some statements in yb_pg_json test
* Remove intermediate UDT mapping for direct mapping
* Uncomment TODOs in yb_pg_enum regress test
* Update utils to have new UDTOIDs
* Add small test for record types
* Change function name in TestPgRegressTypesUDT.java
* Add test for creating and dropping types
* Rename several regress tests
* Redirect ALTER TYPE to issue #1893
* Create custom primitives for UDTs
* Fix and address #1676 comments in yb_plpgsql
* Address last half of #1156 comments in yb_plpgsql
* Address first half of #1156 comments in yb_plpgsql
* Update yb_plpgsql test expected output
* Support functions returning record type
* Create new debug utility YBCPgDataTypeToStr
* Don't error on domain type
* Update some existing yb_foo regress tests
* Add TODO comment for BYTEAARRAY to BYTEA
* Add tests for creating enums and ranges
* Rename yb_enum to yb_pg_enum
* Copy over CREATE TYPE tests
* Support user-defined enum and base types
* Remove IsYugaByteEnabled check for tup init
* Set base type of user-defined types to BYTEAARRAY
* Enable CREATE TYPE and DROP TYPE

Test Plan:
* `TestPgRegressArrays` java test, particularly `yb_pg_arrays` regress
  test
* `TestPgRegressAuthorization` java test, particularly
  `yb_pg_privileges` regress test
* `TestPgRegressBetaFeatures` java test, particularly `yb_pg_plpgsql`,
  `yb_plpgsql` regress tests
* `TestPgRegressFeature` java test, particularly `yb_feature_types`
  regress test
* `TestPgRegressPgMisc` java test, particularly `yb_pg_case`,
  `yb_pg_identity` regress tests
* `TestPgRegressTypesString` java test, particularly `yb_pg_json`,
  `yb_pg_jsonb` regress tests
* `TestPgRegressTypesUDT` java test, particularly `yb_base_type`,
  `yb_create_type`, `yb_pg_create_type`, `yb_pg_enum`,
  `yb_pg_rangetypes`, `yb_pg_rowtypes`

Unrelated tests that got added or changed:

* `yb_create_function` regress test, involving `TestPgRegressTypesUDT`
  java test
* `yb_create_index`, `yb_pg_create_index` regress tests, involving
  `TestPgRegressMisc`, `TestPgRegressTypesUDT` java tests
* `yb_create_table`, `yb_drop_table` regress tests, involving
  `TestPgRegressTable` java test
* `yb_feature_temp` regress test, involving `TestPgRegressFeature` java
  test
* `yb_pg_copy`, `yb_pg_create_table` regress tests, involving
  `TestPgRegressArrays`, `TestPgRegressBetaFeatures`,
  `TestPgRegressMisc`, `TestPgRegressPgMisc`,
  `TestPgRegressTypesString`, `TestPgRegressTypesUDT` java tests
* `yb_pg_foreign_key` regress test, involving `TestPgForeignKey` java
  test
* `yb_pg_int8` regress test, involving `TestPgRegressAuthorization`,
  `TestPgRegressTypesNumeric`, `TestPgRegressTypesUDT` java tests
* `yb_pg_triggers` regress test, involving `TestPgRegressBetaFeatures`
  java test
* `yb_select`, `yb_sequence` regress tests, involving
  `TestPgRegressPgMisc` java test
* `yb_triggers` regress test, involving `TestPgRegressBetaFeatures` java
  test

Reviewers: mihnea, neha

Reviewed By: neha

Subscribers: neil, kannan, yql

Differential Revision: https://phabricator.dev.yugabyte.com/D6900
@jaki jaki closed this as completed Aug 26, 2019
YSQL automation moved this from In progress to Done Aug 26, 2019
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
Projects
YSQL
  
Done
Development

No branches or pull requests

4 participants