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

[Enhancement] Optimize performance of arrays_overlaping (backport #49668) #51539

Merged
merged 2 commits into from
Sep 30, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Sep 29, 2024

Why I'm doing:

Datum is not an efficient data structure, and arrrasy_overlapping heavily relies on Datum for processing, resulting in poor performance.

The second parameter of arrrasy_overlapping is usually const, but there is currently no special handling.

What I'm doing:

PerformaceTest: 27.76s -> 2.74s

mysql> select count(*) from lineorder;
+-----------+
| count(*)  |
+-----------+
| 143999468 |
+-----------+
1 row in set (5.17 sec)

CREATE TABLE `t2` (
  `c1` bigint(20) NOT NULL COMMENT "",
  `c2` array<varchar(65533)> NOT NULL COMMENT "",
  `c3` array<varchar(65533)> NOT NULL COMMENT ""
) ENGINE=OLAP 
DUPLICATE KEY(`c1`)
DISTRIBUTED BY HASH(`c1`) BUCKETS 1 
PROPERTIES (
"compression" = "LZ4",
"fast_schema_evolution" = "true",
"replicated_storage" = "true",
"replication_num" = "1"
);

insert into t2 select lo_orderkey, array_agg(lo_partkey), array_agg(lo_suppkey) from lineorder group by lo_orderkey;

mysql> select count(*) from t2;
+----------+
| count(*) |
+----------+
| 30000000 |
+----------+
1 row in set (0.36 sec)

Before optimization: 27.76s

mysql> select count(*) from t2 where arrays_overlap(c2, ["1", "11", "111", "1111", "11111", "111111", "1111111"]);                                                                                                                                                                
+----------+                                                                                                                                                                                                                                                                      
| count(*) |                                                                                                                                                                                                                                                                      
+----------+                                                                                                                                                                                                                                                                      
|     1204 |                                                                                                                                                                                                                                                                      
+----------+                                                                                                                                                                                                                                                                      
1 row in set (27.76 sec)  

After optimization: 2.74s

mysql> select count(*) from t2 where arrays_overlap(c2, ["1", "11", "111", "1111", "11111", "111111", "1111111"]);                                                                                                                                                                
+----------+                                                                                                                                                                                                                                                                      
| count(*) |                                                                                                                                                                                                                                                                      
+----------+                                                                                                                                                                                                                                                                      
|     1204 |                                                                                                                                                                                                                                                                      
+----------+                                                                                                                                                                                                                                                                      
1 row in set (2.74 sec)

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

Documentation PRs only:

If you are submitting a PR that adds or changes English documentation and have not
included Chinese documentation, then you can check the box to request GPT to translate the
English doc to Chinese. Please ensure to uncheck the Do not translate box if translation is needed.
The workflow will generate a new PR with the Chinese translation after this PR is merged.

  • Yes, translate English markdown files with GPT
  • Do not translate

This is an automatic backport of pull request #49668 done by [Mergify](https://mergify.com). ## Why I'm doing:

Datum is not an efficient data structure, and arrrasy_overlapping heavily relies on Datum for processing, resulting in poor performance.

The second parameter of arrrasy_overlapping is usually const, but there is currently no special handling.

What I'm doing:

PerformaceTest: 27.76s -> 2.74s

mysql> select count(*) from lineorder;
+-----------+
| count(*)  |
+-----------+
| 143999468 |
+-----------+
1 row in set (5.17 sec)

CREATE TABLE `t2` (
  `c1` bigint(20) NOT NULL COMMENT "",
  `c2` array<varchar(65533)> NOT NULL COMMENT "",
  `c3` array<varchar(65533)> NOT NULL COMMENT ""
) ENGINE=OLAP 
DUPLICATE KEY(`c1`)
DISTRIBUTED BY HASH(`c1`) BUCKETS 1 
PROPERTIES (
"compression" = "LZ4",
"fast_schema_evolution" = "true",
"replicated_storage" = "true",
"replication_num" = "1"
);

insert into t2 select lo_orderkey, array_agg(lo_partkey), array_agg(lo_suppkey) from lineorder group by lo_orderkey;

mysql> select count(*) from t2;
+----------+
| count(*) |
+----------+
| 30000000 |
+----------+
1 row in set (0.36 sec)

Before optimization: 27.76s

mysql> select count(*) from t2 where arrays_overlap(c2, ["1", "11", "111", "1111", "11111", "111111", "1111111"]);                                                                                                                                                                
+----------+                                                                                                                                                                                                                                                                      
| count(*) |                                                                                                                                                                                                                                                                      
+----------+                                                                                                                                                                                                                                                                      
|     1204 |                                                                                                                                                                                                                                                                      
+----------+                                                                                                                                                                                                                                                                      
1 row in set (27.76 sec)  

After optimization: 2.74s

mysql> select count(*) from t2 where arrays_overlap(c2, ["1", "11", "111", "1111", "11111", "111111", "1111111"]);                                                                                                                                                                
+----------+                                                                                                                                                                                                                                                                      
| count(*) |                                                                                                                                                                                                                                                                      
+----------+                                                                                                                                                                                                                                                                      
|     1204 |                                                                                                                                                                                                                                                                      
+----------+                                                                                                                                                                                                                                                                      
1 row in set (2.74 sec)

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

@trueeyu
Copy link
Contributor

trueeyu commented Sep 30, 2024

@Mergifyio rebase branch-3.3

Signed-off-by: trueeyu <[email protected]>
Copy link
Contributor Author

mergify bot commented Sep 30, 2024

rebase branch-3.3

✅ Branch has been successfully rebased

@trueeyu trueeyu force-pushed the mergify/bp/branch-3.3/pr-49668 branch from 521094b to c0c2f2e Compare September 30, 2024 05:54
Copy link

sonarcloud bot commented Sep 30, 2024

@wanpengfei-git wanpengfei-git merged commit dab58f7 into branch-3.3 Sep 30, 2024
28 checks passed
@wanpengfei-git wanpengfei-git deleted the mergify/bp/branch-3.3/pr-49668 branch September 30, 2024 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants