CREATETABLE t2 (id int, info text) USING columnar; SELECT columnar.alter_columnar_table_set('t2', chunk_group_row_limit =>'11000'); INSERTINTO t2 SELECT id, md5(id::text) FROM generate_series(1, 10000000) id; SELECTcount(*) FROM t2;
Test-Case-01-Output
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. The connection to the server was lost. Attempting reset: Failed.
通过 GDB 调试其崩溃时的堆栈如下所示。
GDB-Backtrace
#0 ReadStripeNextVector (stripeReadState=0x5575fc19e768, columnValues=0x5575fc1540a0, columnNulls=0x5575fc1540b0, newVectorSize=0x7ffdf9495ea0, stripeId=1, snapshot=0x5575fc0283b8, rowNumber=0x5575fc140820, stripeFirstRowNumber=1) at columnar_reader.c:2166 #1 0x00007fb8037bc42c in ColumnarReadNextVector (readState=0x5575fc19c7e8, columnValues=0x5575fc1540a0, columnNulls=0x5575fc1540b0, rowNumber=0x5575fc140820, newVectorSize=0x7ffdf9495ea0) at columnar_reader.c:2057 #2 0x00007fb8037befb8 in columnar_getnextslot (sscan=0x5575fc19c758, direction=ForwardScanDirection, slot=0x5575fc13e0c8) at columnar_tableam.c:385 #3 0x00007fb8037aafe0 in table_scan_getnextslot (sscan=0x5575fc19c758, direction=ForwardScanDirection, slot=0x5575fc13e0c8) at /data/japin/codes/postgres/build/pg/include/server/access/tableam.h:1066 #4 0x00007fb8037aeeeb in ColumnarScanNext (columnarScanState=0x5575fc0d02f0) at columnar_customscan.c:2544 #5 0x00007fb8037ae7e9 in ExecScanFetch (node=0x5575fc0d02f0, accessMtd=0x7fb8037aed2f <ColumnarScanNext>, recheckMtd=0x7fb8037aef21 <ColumnarScanRecheck>) at columnar_customscan.c:2257 #6 0x00007fb8037ae9e6 in CustomExecScan (columnarScanState=0x5575fc0d02f0, accessMtd=0x7fb8037aed2f <ColumnarScanNext>, recheckMtd=0x7fb8037aef21 <ColumnarScanRecheck>) at columnar_customscan.c:2353 #7 0x00007fb8037aef65 in ColumnarScan_ExecCustomScan (node=0x5575fc0d02f0) at columnar_customscan.c:2576 #8 0x00005575f990c1d3 in ExecCustomScan (pstate=0x5575fc0d02f0) at /data/japin/codes/postgres/build/../src/backend/executor/nodeCustom.c:124 #9 0x00007fb8037e1df6 in ExecProcNode (node=0x5575fc0d02f0) at /data/japin/codes/postgres/build/pg/include/server/executor/executor.h:273 #10 0x00007fb8037e2355 in fetch_input_tuple (aggstate=0x5575fc0cfc88) at vectorization/nodes/columnar_aggregator_node.c:639 #11 0x00007fb8037e5a66 in agg_retrieve_direct (vectoraggstate=0x5575fc0cf658) at vectorization/nodes/columnar_aggregator_node.c:2619 #12 0x00007fb8037e53c4 in ExecAgg (pstate=0x5575fc0cf658) at vectorization/nodes/columnar_aggregator_node.c:2311 #13 0x00007fb8037eac1f in ExecVectorAgg (node=0x5575fc0cf658) at vectorization/nodes/columnar_aggregator_node.c:5316 #14 0x00005575f990c1d3 in ExecCustomScan (pstate=0x5575fc0cf658) at /data/japin/codes/postgres/build/../src/backend/executor/nodeCustom.c:124 #15 0x00005575f98eda69 in ExecProcNodeFirst (node=0x5575fc0cf658) at /data/japin/codes/postgres/build/../src/backend/executor/execProcnode.c:464 #16 0x00005575f990e406 in ExecProcNode (node=0x5575fc0cf658) at /data/japin/codes/postgres/build/../src/include/executor/executor.h:273 #17 0x00005575f990eaf0 in gather_getnext (gatherstate=0x5575fc0cf4b8) at /data/japin/codes/postgres/build/../src/backend/executor/nodeGather.c:295 #18 0x00005575f990e953 in ExecGather (pstate=0x5575fc0cf4b8) at /data/japin/codes/postgres/build/../src/backend/executor/nodeGather.c:227 #19 0x00005575f98eda69 in ExecProcNodeFirst (node=0x5575fc0cf4b8) at /data/japin/codes/postgres/build/../src/backend/executor/execProcnode.c:464 #20 0x00005575f98fd84a in ExecProcNode (node=0x5575fc0cf4b8) at /data/japin/codes/postgres/build/../src/include/executor/executor.h:273 #21 0x00005575f98fdda3 in fetch_input_tuple (aggstate=0x5575fc0cee90) at /data/japin/codes/postgres/build/../src/backend/executor/nodeAgg.c:562 #22 0x00005575f9901358 in agg_retrieve_direct (aggstate=0x5575fc0cee90) at /data/japin/codes/postgres/build/../src/backend/executor/nodeAgg.c:2365 #23 0x00005575f9900f2e in ExecAgg (pstate=0x5575fc0cee90) at /data/japin/codes/postgres/build/../src/backend/executor/nodeAgg.c:2180 #24 0x00005575f98eda69 in ExecProcNodeFirst (node=0x5575fc0cee90) at /data/japin/codes/postgres/build/../src/backend/executor/execProcnode.c:464 #25 0x00005575f98e0b10 in ExecProcNode (node=0x5575fc0cee90) at /data/japin/codes/postgres/build/../src/include/executor/executor.h:273 #26 0x00005575f98e3ac8 in ExecutePlan (estate=0x5575fc0cec18, planstate=0x5575fc0cee90, use_parallel_mode=true, operation=CMD_SELECT, sendTuples=true, numberTuples=0, direction=ForwardScanDirection, dest=0x5575fc115d18, execute_once=true) at /data/japin/codes/postgres/build/../src/backend/executor/execMain.c:1670 #27 0x00005575f98e11f8 in standard_ExecutorRun (queryDesc=0x5575fc103a28, direction=ForwardScanDirection, count=0, execute_once=true) at /data/japin/codes/postgres/build/../src/backend/executor/execMain.c:365 #28 0x00005575f98e1001 in ExecutorRun (queryDesc=0x5575fc103a28, direction=ForwardScanDirection, count=0, execute_once=true) at /data/japin/codes/postgres/build/../src/backend/executor/execMain.c:309 #29 0x00005575f9ba356d in PortalRunSelect (portal=0x5575fc072cc8, forward=true, count=0, dest=0x5575fc115d18) at /data/japin/codes/postgres/build/../src/backend/tcop/pquery.c:924 #30 0x00005575f9ba3194 in PortalRun (portal=0x5575fc072cc8, count=9223372036854775807, isTopLevel=true, run_once=true, dest=0x5575fc115d18, altdest=0x5575fc115d18, qc=0x7ffdf94967e0) at /data/japin/codes/postgres/build/../src/backend/tcop/pquery.c:768 #31 0x00005575f9b9bf52 in exec_simple_query (query_string=0x5575fbff60d8 "SELECT count(*) FROM t2;") at /data/japin/codes/postgres/build/../src/backend/tcop/postgres.c:1274 #32 0x00005575f9ba0fc1 in PostgresMain (dbname=0x5575fbf60058 "postgres", username=0x5575fc02cb58 "japin") at /data/japin/codes/postgres/build/../src/backend/tcop/postgres.c:4637 #33 0x00005575f9ac195a in BackendRun (port=0x5575fc01fd90) at /data/japin/codes/postgres/build/../src/backend/postmaster/postmaster.c:4464 #34 0x00005575f9ac11e6 in BackendStartup (port=0x5575fc01fd90) at /data/japin/codes/postgres/build/../src/backend/postmaster/postmaster.c:4192 #35 0x00005575f9abd471 in ServerLoop () at /data/japin/codes/postgres/build/../src/backend/postmaster/postmaster.c:1782 #36 0x00005575f9abcd1b in PostmasterMain (argc=1, argv=0x5575fbf5e010) at /data/japin/codes/postgres/build/../src/backend/postmaster/postmaster.c:1466 #37 0x00005575f9970914 in main (argc=1, argv=0x5575fbf5e010) at /data/japin/codes/postgres/build/../src/backend/main/main.c:198
staticbool ReadStripeNextVector(StripeReadState *stripeReadState, Datum *columnValues, bool *columnNulls, int *newVectorSize, uint64 stripeId, Snapshot snapshot, uint64 *rowNumber, uint64 stripeFirstRowNumber) { [...]
while (true) { [...]
if (!ReadChunkGroupNextVector(stripeReadState->chunkGroupReadState, columnValues, columnNulls, stripeReadState->tupleDescriptor, columnValueOffset, newVectorSize, rowNumber, chunkFirstRowNumber)) { /* if this chunk group is exhausted, fetch the next one and loop */ EndChunkGroupRead(stripeReadState->chunkGroupReadState); stripeReadState->chunkGroupReadState = NULL; stripeReadState->chunkGroupIndex++;
CREATETABLE t(a INT, b TEXT) USING columnar; SELECT columnar.alter_columnar_table_set('t', chunk_group_row_limit =>'11000'); INSERTINTO t SELECT a, md5(b::text) FROM generate_series(0,50000) AS t1(a) JOINLATERAL generate_series(1, 10) AS t2(b) ON (true); SELECT b, count(*) FROM t WHERE a >50AND b <>''GROUPBY b;
Test-Case-02-Output
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. The connection to the server was lost. Attempting reset: Failed.
其堆栈信息如下所示:
GDB-Backtrace
#0 0x00005588c2b833ff in toast_raw_datum_size (value=22503863415320) at /home/japin/codes/postgres/build/../src/backend/access/common/detoast.c:550 #1 0x00005588c32c69b4 in textne (fcinfo=0x5588c521b718) at /home/japin/codes/postgres/build/../src/backend/utils/adt/varlena.c:1697 #2 0x00005588c2e50dd5 in ExecInterpExpr (state=0x5588c521b688, econtext=0x5588c51f7890, isnull=0x7fffda8cb39f) at /home/japin/codes/postgres/build/../src/backend/executor/execExprInterp.c:758 #3 0x00001477a335cceb in ExecEvalExprSwitchContext (state=0x5588c521b688, econtext=0x5588c51f7890, isNull=0x7fffda8cb39f) at /data/japin/codes/postgres/build/pg/include/server/executor/executor.h:355 #4 0x00001477a335ce1a in ExecQual (state=0x5588c521b688, econtext=0x5588c51f7890) at /data/japin/codes/postgres/build/pg/include/server/executor/executor.h:424 #5 0x00001477a3360c51 in CustomExecScan (columnarScanState=0x5588c51f7680, accessMtd=0x1477a3360d1c <ColumnarScanNext>, recheckMtd=0x1477a3360f0e <ColumnarScanRecheck>) at columnar_customscan.c:2448 #6 0x00001477a3360f52 in ColumnarScan_ExecCustomScan (node=0x5588c51f7680) at columnar_customscan.c:2576 #7 0x00005588c2e88fda in ExecCustomScan (pstate=0x5588c51f7680) at /home/japin/codes/postgres/build/../src/backend/executor/nodeCustom.c:124 #8 0x00005588c2e7a651 in ExecProcNode (node=0x5588c51f7680) at /home/japin/codes/postgres/build/../src/include/executor/executor.h:273 #9 0x00005588c2e7abaa in fetch_input_tuple (aggstate=0x5588c51f7018) at /home/japin/codes/postgres/build/../src/backend/executor/nodeAgg.c:562 #10 0x00005588c2e7e4e3 in agg_fill_hash_table (aggstate=0x5588c51f7018) at /home/japin/codes/postgres/build/../src/backend/executor/nodeAgg.c:2552 #11 0x00005588c2e7dd17 in ExecAgg (pstate=0x5588c51f7018) at /home/japin/codes/postgres/build/../src/backend/executor/nodeAgg.c:2173 #12 0x00005588c2e6a870 in ExecProcNodeFirst (node=0x5588c51f7018) at /home/japin/codes/postgres/build/../src/backend/executor/execProcnode.c:464 #13 0x00005588c2e8b20d in ExecProcNode (node=0x5588c51f7018) at /home/japin/codes/postgres/build/../src/include/executor/executor.h:273 #14 0x00005588c2e8b8f7 in gather_getnext (gatherstate=0x5588c51f6de8) at /home/japin/codes/postgres/build/../src/backend/executor/nodeGather.c:295 #15 0x00005588c2e8b75a in ExecGather (pstate=0x5588c51f6de8) at /home/japin/codes/postgres/build/../src/backend/executor/nodeGather.c:227 #16 0x00005588c2e6a870 in ExecProcNodeFirst (node=0x5588c51f6de8) at /home/japin/codes/postgres/build/../src/backend/executor/execProcnode.c:464 #17 0x00005588c2e7a651 in ExecProcNode (node=0x5588c51f6de8) at /home/japin/codes/postgres/build/../src/include/executor/executor.h:273 #18 0x00005588c2e7abaa in fetch_input_tuple (aggstate=0x5588c51f6780) at /home/japin/codes/postgres/build/../src/backend/executor/nodeAgg.c:562 #19 0x00005588c2e7e4e3 in agg_fill_hash_table (aggstate=0x5588c51f6780) at /home/japin/codes/postgres/build/../src/backend/executor/nodeAgg.c:2552 #20 0x00005588c2e7dd17 in ExecAgg (pstate=0x5588c51f6780) at /home/japin/codes/postgres/build/../src/backend/executor/nodeAgg.c:2173 #21 0x00005588c2e6a870 in ExecProcNodeFirst (node=0x5588c51f6780) at /home/japin/codes/postgres/build/../src/backend/executor/execProcnode.c:464 #22 0x00005588c2eb3951 in ExecProcNode (node=0x5588c51f6780) at /home/japin/codes/postgres/build/../src/include/executor/executor.h:273 #23 0x00005588c2eb3ba1 in ExecSort (pstate=0x5588c51f6570) at /home/japin/codes/postgres/build/../src/backend/executor/nodeSort.c:149 #24 0x00005588c2e6a870 in ExecProcNodeFirst (node=0x5588c51f6570) at /home/japin/codes/postgres/build/../src/backend/executor/execProcnode.c:464 #25 0x00005588c2e9de67 in ExecProcNode (node=0x5588c51f6570) at /home/japin/codes/postgres/build/../src/include/executor/executor.h:273 #26 0x00005588c2e9e0be in ExecLimit (pstate=0x5588c51f6280) at /home/japin/codes/postgres/build/../src/backend/executor/nodeLimit.c:96 #27 0x00005588c2e6a870 in ExecProcNodeFirst (node=0x5588c51f6280) at /home/japin/codes/postgres/build/../src/backend/executor/execProcnode.c:464 #28 0x00005588c2e5d917 in ExecProcNode (node=0x5588c51f6280) at /home/japin/codes/postgres/build/../src/include/executor/executor.h:273 #29 0x00005588c2e608cf in ExecutePlan (estate=0x5588c51f6008, planstate=0x5588c51f6280, use_parallel_mode=true, operation=CMD_SELECT, sendTuples=true, numberTuples=0, direction=ForwardScanDirection, dest=0x5588c520a538, execute_once=true) at /home/japin/codes/postgres/build/../src/backend/executor/execMain.c:1670 #30 0x00005588c2e5dfff in standard_ExecutorRun (queryDesc=0x5588c51d6268, direction=ForwardScanDirection, count=0, execute_once=true) at /home/japin/codes/postgres/build/../src/backend/executor/execMain.c:365 #31 0x00005588c2e5de08 in ExecutorRun (queryDesc=0x5588c51d6268, direction=ForwardScanDirection, count=0, execute_once=true) at /home/japin/codes/postgres/build/../src/backend/executor/execMain.c:309 #32 0x00005588c3120364 in PortalRunSelect (portal=0x5588c51655c8, forward=true, count=0, dest=0x5588c520a538) at /home/japin/codes/postgres/build/../src/backend/tcop/pquery.c:924 #33 0x00005588c311ff8b in PortalRun (portal=0x5588c51655c8, count=9223372036854775807, isTopLevel=true, run_once=true, dest=0x5588c520a538, altdest=0x5588c520a538, qc=0x7fffda8cbbd0) at /home/japin/codes/postgres/build/../src/backend/tcop/pquery.c:768 #34 0x00005588c3118d49 in exec_simple_query ( query_string=0x5588c50e6178 "SELECT\n URL, COUNT(*) AS PageViews FROM hits\nWHERE\n CounterID = 62\n AND EventDate >= '2013-07-01'\n AND EventDate <= '2013-07-31'\n AND DontCountHits = 0\n AND IsRefresh = 0\n AND URL <> ''\nGROUP B"...) at /home/japin/codes/postgres/build/../src/backend/tcop/postgres.c:1274 #35 0x00005588c311ddb8 in PostgresMain (dbname=0x5588c5123370 "postgres", username=0x5588c5123358 "japin") at /home/japin/codes/postgres/build/../src/backend/tcop/postgres.c:4637 #36 0x00005588c303e751 in BackendRun (port=0x5588c510fe90) at /home/japin/codes/postgres/build/../src/backend/postmaster/postmaster.c:4464 #37 0x00005588c303dfdd in BackendStartup (port=0x5588c510fe90) at /home/japin/codes/postgres/build/../src/backend/postmaster/postmaster.c:4192 #38 0x00005588c303a268 in ServerLoop () at /home/japin/codes/postgres/build/../src/backend/postmaster/postmaster.c:1782 #39 0x00005588c3039b12 in PostmasterMain (argc=3, argv=0x5588c504e050) at /home/japin/codes/postgres/build/../src/backend/postmaster/postmaster.c:1466 #40 0x00005588c2eed71b in main (argc=3, argv=0x5588c504e050) at /home/japin/codes/postgres/build/../src/backend/main/main.c:198
(gdb) f 1 #1 0x0000557ddff3eef1 in textne (fcinfo=0x557de0cbd748) at /data/japin/codes/postgres/build/../src/backend/utils/adt/varlena.c:1697 (gdb) p arg1 $1 = 140355960598152 (gdb) p *(Datum *)arg1 Cannot access memory at address 0x7fa72b2c6e88
(gdb) b ReadChunkGroupNextVector Function "ReadChunkGroupNextVector" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (ReadChunkGroupNextVector) pending. (gdb) b columnar_reader.c:2184 No source file named columnar_reader.c. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 2 (columnar_reader.c:2184) pending. (gdb) b columnar_reader.c:2199 No source file named columnar_reader.c. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 3 (columnar_reader.c:2199) pending.
staticbool ReadChunkGroupNextVector(ChunkGroupReadState *chunkGroupReadState, Datum *columnValues, bool *columnNulls, TupleDesc tupleDesc, int32 *columnValueOffset, int *chunkReadRows, uint64 *rowNumber, uint64 stripeFirstRowNumber) { if (chunkGroupReadState->currentRow >= chunkGroupReadState->rowCount) { Assert(chunkGroupReadState->currentRow == chunkGroupReadState->rowCount); returnfalse; }
/* * Initialize to all-NULL. Only non-NULL projected attributes will be set. */ memset(columnNulls, true, sizeof(bool) * chunkGroupReadState->columnCount);
int i; int rowNumberIndex = 0;
for (i = 0; i < chunkGroupReadState->rowCount; i ++) { if (chunkGroupReadState->currentRow >= chunkGroupReadState->rowCount) returnfalse;
diff --git a/columnar/src/backend/columnar/columnar_reader.c b/columnar/src/backend/columnar/columnar_reader.c index b23829f..30448d5 100644 --- a/columnar/src/backend/columnar/columnar_reader.c +++ b/columnar/src/backend/columnar/columnar_reader.c @@ -2154,13 +2154,19 @@ ReadStripeNextVector(StripeReadState *stripeReadState, Datum *columnValues, rowNumber, chunkFirstRowNumber)) { - /* if this chunk group is exhausted, fetch the next one and loop */ - EndChunkGroupRead(stripeReadState->chunkGroupReadState); - stripeReadState->chunkGroupReadState = NULL; - stripeReadState->chunkGroupIndex++; - + /* + * if *newVectorSize is non-zero, it means there might be some data in + * chunkGroupReadState->chunkGroupData referenced by VectorColumn. In + * this case, do NOT release ChunkGroupReadState. + */ if (*newVectorSize == 0) + { + /* if this chunk group is exhausted, fetch the next one and loop */ + EndChunkGroupRead(stripeReadState->chunkGroupReadState); + stripeReadState->chunkGroupReadState = NULL; + stripeReadState->chunkGroupIndex++; continue; + } } else stripeReadState->currentRow += stripeReadState->chunkGroupReadState->rowCount;
备注
上面的查询可能会并行执行,为了减少调试时并行执行带来的困扰,可以在执行 SQL 查询时禁止并行执行,如 SET max_parallel_workers = 0;。