Skip to content

Conversation

@congxuebin
Copy link
Contributor

fix #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;

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hiiii, @congxuebin welcome!🎊 Thanks for taking the effort to make our project better! 🙌 Keep making such awesome contributions!

@my-ship-it
Copy link
Contributor

Please fix pipeline failures.

@congxuebin
Copy link
Contributor Author

congxuebin commented Jul 3, 2024

Hi Max, @my-ship-it

The test case that I changed was successfully executed in the pipeline test. The pipeline failure is due to something else. I will check with Dianjin later about it.

gpdtm_plpgsql ... ok 30142 ms (diff 57 ms)

@congxuebin congxuebin requested a review from my-ship-it July 3, 2024 02:40
@my-ship-it my-ship-it merged commit 8457bf6 into apache:main Jul 3, 2024
foreyes pushed a commit to foreyes/cloudberrydb that referenced this pull request Sep 20, 2024
)

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;

(cherry picked from commit 8457bf6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] order unexpected, when inserting array data into a table with an auto-increment column

2 participants