From 810c2b14373153a1b99755b863090d6c762a205f Mon Sep 17 00:00:00 2001 From: Japin Li Date: Fri, 2 Feb 2024 01:19:37 +0800 Subject: [PATCH] Fix a server crash (#235) When chunk_group_row_limit is bigger than 110000, there is a crash caused by ReadStripeNextVector(). --- .../src/backend/columnar/columnar_reader.c | 6 +++--- .../expected/columnar_alter_set_type.out | 4 ++-- .../test/regress/expected/columnar_query.out | 18 ++++++++++++++++++ .../src/test/regress/sql/columnar_query.sql | 17 ++++++++++++++++- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/columnar/src/backend/columnar/columnar_reader.c b/columnar/src/backend/columnar/columnar_reader.c index b24e4d17..b23829f3 100644 --- a/columnar/src/backend/columnar/columnar_reader.c +++ b/columnar/src/backend/columnar/columnar_reader.c @@ -2162,8 +2162,8 @@ ReadStripeNextVector(StripeReadState *stripeReadState, Datum *columnValues, if (*newVectorSize == 0) continue; } - - stripeReadState->currentRow += stripeReadState->chunkGroupReadState->rowCount; + else + stripeReadState->currentRow += stripeReadState->chunkGroupReadState->rowCount; return true; } @@ -2260,4 +2260,4 @@ ReadChunkGroupNextVector(ChunkGroupReadState *chunkGroupReadState, Datum *column } return true; -} \ No newline at end of file +} diff --git a/columnar/src/test/regress/expected/columnar_alter_set_type.out b/columnar/src/test/regress/expected/columnar_alter_set_type.out index 72f16a25..204a4fcb 100644 --- a/columnar/src/test/regress/expected/columnar_alter_set_type.out +++ b/columnar/src/test/regress/expected/columnar_alter_set_type.out @@ -63,7 +63,7 @@ SELECT columnar.alter_columnar_table_set('test', compression => 'lz4'); INSERT INTO test VALUES(1); VACUUM VERBOSE test; INFO: statistics for "test": -storage id: 10000000141 +storage id: 10000000142 total file size: 24576, total data size: 6 compression rate: 0.83x total row count: 1, stripe count: 1, average rows per stripe: 1 @@ -72,7 +72,7 @@ chunk count: 1, containing data for dropped columns: 0, lz4 compressed: 1 ALTER TABLE test ALTER COLUMN i TYPE int8; VACUUM VERBOSE test; INFO: statistics for "test": -storage id: 10000000142 +storage id: 10000000143 total file size: 24576, total data size: 10 compression rate: 0.90x total row count: 1, stripe count: 1, average rows per stripe: 1 diff --git a/columnar/src/test/regress/expected/columnar_query.out b/columnar/src/test/regress/expected/columnar_query.out index 72664c73..95b78db0 100644 --- a/columnar/src/test/regress/expected/columnar_query.out +++ b/columnar/src/test/regress/expected/columnar_query.out @@ -310,3 +310,21 @@ SELECT * FROM t WHERE a >= 90; (11 rows) DROP TABLE t; +-- +-- [columnar] Test chunk_group_row_limit +-- +CREATE TABLE t(a INT) USING columnar; +SELECT columnar.alter_columnar_table_set('t', chunk_group_row_limit => '11000'); + alter_columnar_table_set +-------------------------- + +(1 row) + +INSERT INTO t SELECT a FROM generate_series(0,50000) AS a; +SELECT count(*) FROM t; + count +------- + 50001 +(1 row) + +DROP TABLE t; diff --git a/columnar/src/test/regress/sql/columnar_query.sql b/columnar/src/test/regress/sql/columnar_query.sql index d3c58ae5..f78bc1f2 100644 --- a/columnar/src/test/regress/sql/columnar_query.sql +++ b/columnar/src/test/regress/sql/columnar_query.sql @@ -159,4 +159,19 @@ SELECT * FROM t WHERE a >= 90; SELECT * FROM t WHERE a >= 90; -DROP TABLE t; \ No newline at end of file +DROP TABLE t; + + +-- +-- [columnar] Test chunk_group_row_limit +-- + +CREATE TABLE t(a INT) USING columnar; + +SELECT columnar.alter_columnar_table_set('t', chunk_group_row_limit => '11000'); + +INSERT INTO t SELECT a FROM generate_series(0,50000) AS a; + +SELECT count(*) FROM t; + +DROP TABLE t;