Skip to content

Commit 8457bf6

Browse files
authored
Resolve inconsistent result issue in gpdtm_plpgsql test case (apache#491)
Fix apache#478 Change logs ICW testcase gpdtm_plpgsql failed intermittently. The result of the following statements is not consistent. CREATE TABLE test_parse_arr (a bigserial, b int[]); -- parse_arr function is defined as a udf to convert string into in array, but it is not important to this issue INSERT INTO test_parse_arr (b) SELECT parse_arr(x) as pr FROM ( SELECT '(1, 2, 3)' AS x UNION ALL SELECT NULL UNION ALL SELECT '(4, 5, 6)' AS x ) AS q order by pr ; SELECT * FROM test_parse_arr ORDER BY a; Here are results from two separate executions. a | b ---+----------- 1 | {{4,5,6}} 2 | {{1,2,3}} 3 | (3 rows) a | b ---+----------- 1 | 2 | {{1,2,3}} 3 | {{4,5,6}} (3 rows) It is not a cbdb bug. Even though the ORDER BY clause in the INSERT statement ensures the elements in array b are ordered, due to data distribution mechanics—where data is dispatched to different nodes for processing — the sequential generation of auto-increment values(for column a) across these nodes cannot be consistently guaranteed. Consequently, when querying "SELECT * FROM test_parse_arr ORDER BY a" the resulting sequence may not reflect the initial order of the array elements as they were inserted. The test case need to be modified to make sure test result consistent. Instead of verifying result via "SELECT * FROM test_parse_arr ORDER BY a" , verify column a and b separately as following: SELECT a FROM test_parse_arr ORDER BY a; SELECT b FROM test_parse_arr ORDER BY b;
1 parent 705ee0b commit 8457bf6

2 files changed

Lines changed: 37 additions & 20 deletions

File tree

src/test/regress/expected/gpdtm_plpgsql.out

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -536,18 +536,30 @@ CREATE TABLE test_parse_arr (a bigserial, b int[]);
536536
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Cloudberry Database data distribution key for this table.
537537
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
538538
INSERT INTO test_parse_arr (b)
539-
SELECT parse_arr(x) FROM
540-
(
541-
SELECT '(1, 2, 3)' AS x
542-
UNION ALL
543-
SELECT NULL
544-
) AS q;
545-
SELECT * FROM test_parse_arr ORDER BY a;
546-
a | b
547-
---+-----------
548-
1 | {{1,2,3}}
549-
2 |
550-
(2 rows)
539+
SELECT parse_arr(x) FROM
540+
(
541+
SELECT '(1, 2, 3)' AS x
542+
UNION ALL
543+
SELECT NULL AS x
544+
UNION ALL
545+
SELECT '(4, 5, 6)' AS x
546+
ORDER BY x
547+
) AS q;
548+
SELECT a FROM test_parse_arr ORDER BY a;
549+
a
550+
---
551+
1
552+
2
553+
3
554+
(3 rows)
555+
556+
SELECT b FROM test_parse_arr ORDER BY b;
557+
b
558+
-----------
559+
{{1,2,3}}
560+
{{4,5,6}}
561+
562+
(3 rows)
551563

552564
--
553565
-- Test if sequence server information outlives a plpgsql exception and corresponding subtransaction rollback (MPP-25193)

src/test/regress/sql/gpdtm_plpgsql.sql

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,19 @@ $dbvis$ LANGUAGE plpgsql;
302302
CREATE TABLE test_parse_arr (a bigserial, b int[]);
303303

304304
INSERT INTO test_parse_arr (b)
305-
SELECT parse_arr(x) FROM
306-
(
307-
SELECT '(1, 2, 3)' AS x
308-
UNION ALL
309-
SELECT NULL
310-
) AS q;
311-
312-
SELECT * FROM test_parse_arr ORDER BY a;
305+
SELECT parse_arr(x) FROM
306+
(
307+
SELECT '(1, 2, 3)' AS x
308+
UNION ALL
309+
SELECT NULL AS x
310+
UNION ALL
311+
SELECT '(4, 5, 6)' AS x
312+
ORDER BY x
313+
) AS q;
314+
315+
SELECT a FROM test_parse_arr ORDER BY a;
316+
317+
SELECT b FROM test_parse_arr ORDER BY b;
313318

314319
--
315320
-- Test if sequence server information outlives a plpgsql exception and corresponding subtransaction rollback (MPP-25193)

0 commit comments

Comments
 (0)