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

chore: test Mergeinto runtime filter performance and wizard #14212

Merged
merged 74 commits into from
Jan 4, 2024

Conversation

JackTan25
Copy link
Contributor

@JackTan25 JackTan25 commented Jan 3, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

we try to merge the merge-into-runtime-filter branch.

  1. we trun on the broadcast join button in merge into optimizer.
  2. we use query optimizer result when change join order.
  3. we test performance and corrects for this pr and passed wizard, test scripts, and more important performance
    test which doesn't increase.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

Copy link
Contributor

github-actions bot commented Jan 3, 2024

Docker Image for PR

  • tag: pr-14212-6b8c41b

note: this image tag is only available for internal use,
please check the internal doc for more details.

@JackTan25
Copy link
Contributor Author

JackTan25 commented Jan 4, 2024

Click me
deploy@(merge_into_runtime_filter)/test> merge into small_target as t1 using (select * from target_table_cluster) as t2 on t1.l_partkey = t2.l_partkey and t1.l_orderkey = t2.l_orderkey and t1.l_suppkey = t2.l_suppkey and t1.l_linenumber = t2.l_linenumber and t1.l_shipdate = t2.l_shipdate when matched  then update *;

MERGE INTO small_target AS t1 USING (
  SELECT
    *
  FROM
    target_table_cluster
) AS t2 ON t1.l_partkey = t2.l_partkey
AND t1.l_orderkey = t2.l_orderkey
AND t1.l_suppkey = t2.l_suppkey
AND t1.l_linenumber = t2.l_linenumber
AND t1.l_shipdate = t2.l_shipdate
WHEN matched THEN
UPDATE
  *

┌────────────────────────┐
│ number of rows updated │
│          Int32         │
├────────────────────────┤
│                 500000 │
└────────────────────────┘
1 row read in 9.242 sec. Processed 1 million row, 164.99 MiB (108.2 thousand row/s, 17.85 MiB/s)

deploy@(merge_into_runtime_filter)/test> show tables;

SHOW TABLES

┌────────────────────────┐
│ Tables_in_test │
│         String         │
├────────────────────────┤
│ cluster_source         │
│ cluster_target         │
│ large_source           │
│ small_target           │
│ source_table           │
│ target_table           │
│ target_table_120       │
│ target_table_24        │
│ target_table_cluster   │
│ tmp                    │
└────────────────────────┘
10 rows read in 1.251 sec. Processed 10 rows, 2.07 KiB (7.99 rows/s, 1.65 KiB/s)

deploy@(merge_into_runtime_filter)/test> merge into target_table_cluster as t1 using (select * from source_table) as t2 on t1.l_partkey = t2.l_partkey and t1.l_orderkey = t2.l_orderkey and t1.l_suppkey = t2.l_suppkey and t1.l_linenumber = t2.l_linenumber and t1.l_shipdate = t2.l_shipdate when matched  then update *;

MERGE INTO target_table_cluster AS t1 USING (
  SELECT
    *
  FROM
    source_table
) AS t2 ON t1.l_partkey = t2.l_partkey
AND t1.l_orderkey = t2.l_orderkey
AND t1.l_suppkey = t2.l_suppkey
AND t1.l_linenumber = t2.l_linenumber
AND t1.l_shipdate = t2.l_shipdate
WHEN matched THEN
UPDATE
  *

┌────────────────────────┐
│ number of rows updated │
│          Int32         │
├────────────────────────┤
│                 500000 │
└────────────────────────┘
1 row read in 11.430 sec. Processed 1 million row, 164.99 MiB (87.49 thousand row/s, 14.43 MiB/s)

after fix runtime filter constraint, we can get good performance.

@JackTan25
Copy link
Contributor Author

distributed mode passed in wizard:

Click me
Preparing to run MERGE-INTO-C1...
Executing command: bendsql --query=-- MERGE-INTO-C1: Asset Types Distribution
SELECT asset_type, COUNT(*) AS count
FROM assets
GROUP BY asset_type
ORDER BY count DESC, asset_type
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
NEW_ASSET       150000
BTC     104817
ETH     104808
XRP     90375

Executing command: snowsql --query -- MERGE-INTO-C1: Asset Types Distribution
SELECT asset_type, COUNT(*) AS count
FROM assets
GROUP BY asset_type
ORDER BY count DESC, asset_type
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
NEW_ASSET       150000
BTC     104817
ETH     104808
XRP     90375

OK - MERGE-INTO-C1
NEW_ASSET       150000
BTC     104817
ETH     104808
XRP     90375

Preparing to run MERGE-INTO-C2...
Executing command: bendsql --query=

-- MERGE-INTO-C2: Aggregated Quantity and Value Statistics
SELECT SUM(quantity) AS total_quantity,
       AVG(quantity) AS average_quantity,
       SUM(value) AS total_value,
       AVG(value) AS average_value
FROM assets -D mergeinto
Command executed successfully. Output:
165342725.20941540      367.428278243145        1653427252.09414242     3674.282782431428

Executing command: snowsql --query 

-- MERGE-INTO-C2: Aggregated Quantity and Value Statistics
SELECT SUM(quantity) AS total_quantity,
       AVG(quantity) AS average_quantity,
       SUM(value) AS total_value,
       AVG(value) AS average_value
FROM assets --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
165342725.20941540      367.428278243145        1653427252.09414242     3674.282782431428

OK - MERGE-INTO-C2
165342725.20941540      367.428278243145        1653427252.09414242     3674.282782431428

Preparing to run MERGE-INTO-C3...
Executing command: bendsql --query=

-- MERGE-INTO-C3: Assets Counts by User
SELECT user_id, COUNT(*) AS count
FROM assets
GROUP BY user_id
ORDER BY count DESC, user_id
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
0       6
2       6
4       6
6       6
8       6
10      6
12      6
14      6
16      6
18      6
20      6
22      6
24      6

Executing command: snowsql --query 

-- MERGE-INTO-C3: Assets Counts by User
SELECT user_id, COUNT(*) AS count
FROM assets
GROUP BY user_id
ORDER BY count DESC, user_id
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
0       6
2       6
4       6
6       6
8       6
10      6
12      6
14      6
16      6
18      6
20      6
22      6
24      6

OK - MERGE-INTO-C3
0       6
2       6
4       6
6       6
8       6
10      6
12      6
14      6
16      6
18      6
20      6
22      6
24      6

Preparing to run MERGE-INTO-C4...
Executing command: bendsql --query=

-- MERGE-INTO-C4: Date Range Analysis of Last Update
SELECT CASE
           WHEN last_updated < '2022-01-01' THEN 'Before 2022'
           ELSE 'After 2021-12-31'
           END AS date_range,
       COUNT(*) AS count
FROM assets
GROUP BY date_range
ORDER BY date_range
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
After 2021-12-31        410014
Before 2022     39986

Executing command: snowsql --query 

-- MERGE-INTO-C4: Date Range Analysis of Last Update
SELECT CASE
           WHEN last_updated < '2022-01-01' THEN 'Before 2022'
           ELSE 'After 2021-12-31'
           END AS date_range,
       COUNT(*) AS count
FROM assets
GROUP BY date_range
ORDER BY date_range
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
After 2021-12-31        410014
Before 2022     39986

OK - MERGE-INTO-C4
After 2021-12-31        410014
Before 2022     39986

Preparing to run MERGE-INTO-C5...
Executing command: bendsql --query=

-- MERGE-INTO-C5: General Status Distribution
SELECT status, COUNT(*) AS count
FROM orders
GROUP BY status
ORDER BY count DESC, status
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
avg     1049532
completed       350986
pending 348300
cancelled       300714
Pending 150000
above_avg       100418
below_avg       100075

Executing command: snowsql --query 

-- MERGE-INTO-C5: General Status Distribution
SELECT status, COUNT(*) AS count
FROM orders
GROUP BY status
ORDER BY count DESC, status
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
avg     1049532
completed       350986
pending 348300
cancelled       300714
Pending 150000
above_avg       100418
below_avg       100075

OK - MERGE-INTO-C5
avg     1049532
completed       350986
pending 348300
cancelled       300714
Pending 150000
above_avg       100418
below_avg       100075

Preparing to run MERGE-INTO-C6...
Executing command: bendsql --query=

-- MERGE-INTO-C6: General Quantity Statistics
SELECT SUM(quantity) AS total_quantity,
       AVG(quantity) AS average_quantity,
       MIN(quantity) AS min_quantity,
       MAX(quantity) AS max_quantity
FROM orders -D mergeinto
Command executed successfully. Output:
1526855542.46298600     636.183182451427        0.00005807      8910.78518320

Executing command: snowsql --query 

-- MERGE-INTO-C6: General Quantity Statistics
SELECT SUM(quantity) AS total_quantity,
       AVG(quantity) AS average_quantity,
       MIN(quantity) AS min_quantity,
       MAX(quantity) AS max_quantity
FROM orders --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
1526855542.46298600     636.183182451427        0.00005807      8910.78518320

OK - MERGE-INTO-C6
1526855542.46298600     636.183182451427        0.00005807      8910.78518320

Preparing to run MERGE-INTO-C7...
Executing command: bendsql --query=

-- MERGE-INTO-C7: New Orders vs Existing Orders Count
SELECT CASE
           WHEN order_id > 500000 THEN 'New Order'
           ELSE 'Existing Order'
           END AS order_category,
       COUNT(*) AS count
FROM orders
GROUP BY order_category
ORDER BY count DESC
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
New Order       1649995
Existing Order  750030

Executing command: snowsql --query 

-- MERGE-INTO-C7: New Orders vs Existing Orders Count
SELECT CASE
           WHEN order_id > 500000 THEN 'New Order'
           ELSE 'Existing Order'
           END AS order_category,
       COUNT(*) AS count
FROM orders
GROUP BY order_category
ORDER BY count DESC
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
New Order       1649995
Existing Order  750030

OK - MERGE-INTO-C7
New Order       1649995
Existing Order  750030

Preparing to run MERGE-INTO-C8...
Executing command: bendsql --query=

-- MERGE-INTO-C8: Order Type Distribution
SELECT order_type, COUNT(*) AS count
FROM orders
GROUP BY order_type
ORDER BY count DESC, order_type
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
buy     1274986
sell    1125039

Executing command: snowsql --query 

-- MERGE-INTO-C8: Order Type Distribution
SELECT order_type, COUNT(*) AS count
FROM orders
GROUP BY order_type
ORDER BY count DESC, order_type
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
buy     1274986
sell    1125039

OK - MERGE-INTO-C8
buy     1274986
sell    1125039

Preparing to run MERGE-INTO-C9...
Executing command: bendsql --query=

-- MERGE-INTO-C9: Date Range Analysis
SELECT CASE
           WHEN created_at < '2022-01-01' THEN 'Before 2022'
           WHEN created_at BETWEEN '2021-01-01' AND '2021-06-30' THEN 'First Half 2021'
           ELSE 'After 2021-06-30'
           END AS date_range,
       COUNT(*) AS count
FROM orders
GROUP BY date_range
ORDER BY date_range
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
After 2021-06-30        150000
Before 2022     2250025

Executing command: snowsql --query 

-- MERGE-INTO-C9: Date Range Analysis
SELECT CASE
           WHEN created_at < '2022-01-01' THEN 'Before 2022'
           WHEN created_at BETWEEN '2021-01-01' AND '2021-06-30' THEN 'First Half 2021'
           ELSE 'After 2021-06-30'
           END AS date_range,
       COUNT(*) AS count
FROM orders
GROUP BY date_range
ORDER BY date_range
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
After 2021-06-30        150000
Before 2022     2250025

OK - MERGE-INTO-C9
After 2021-06-30        150000
Before 2022     2250025

Preparing to run MERGE-INTO-C10...
Executing command: bendsql --query=

-- MERGE-INTO-C10: Price Analysis After Adjustments
SELECT SUM(price) AS total_price,
       AVG(price) AS average_price,
       MIN(price) AS min_price,
       MAX(price) AS max_price
FROM orders -D mergeinto
Command executed successfully. Output:
2874615680.22030825     1197.744056924535       0.00058074      10990.07262787

Executing command: snowsql --query 

-- MERGE-INTO-C10: Price Analysis After Adjustments
SELECT SUM(price) AS total_price,
       AVG(price) AS average_price,
       MIN(price) AS min_price,
       MAX(price) AS max_price
FROM orders --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
2874615680.22030825     1197.744056924535       0.00058074      10990.07262787

OK - MERGE-INTO-C10
2874615680.22030825     1197.744056924535       0.00058074      10990.07262787

Preparing to run MERGE-INTO-C11...
Executing command: bendsql --query=

-- MERGE-INTO-C11: Transaction Types Distribution
SELECT transaction_type, COUNT(*) AS count
FROM transactions
GROUP BY transaction_type
ORDER BY count DESC, transaction_type
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
trade   505920
deposit 26492
withdrawal      26129

Executing command: snowsql --query 

-- MERGE-INTO-C11: Transaction Types Distribution
SELECT transaction_type, COUNT(*) AS count
FROM transactions
GROUP BY transaction_type
ORDER BY count DESC, transaction_type
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
trade   505920
deposit 26492
withdrawal      26129

OK - MERGE-INTO-C11
trade   505920
deposit 26492
withdrawal      26129

Preparing to run MERGE-INTO-C12...
Executing command: bendsql --query=

-- MERGE-INTO-C12: Aggregated Quantity Statistics
SELECT SUM(quantity) AS total_quantity,
       AVG(quantity) AS average_quantity,
       MIN(quantity) AS min_quantity,
       MAX(quantity) AS max_quantity
FROM transactions -D mergeinto
Command executed successfully. Output:
73627261.57298446       131.820692792444        0.00106899      664.06985910

Executing command: snowsql --query 

-- MERGE-INTO-C12: Aggregated Quantity Statistics
SELECT SUM(quantity) AS total_quantity,
       AVG(quantity) AS average_quantity,
       MIN(quantity) AS min_quantity,
       MAX(quantity) AS max_quantity
FROM transactions --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
73627261.57298446       131.820692792444        0.00106899      664.06985910

OK - MERGE-INTO-C12
73627261.57298446       131.820692792444        0.00106899      664.06985910

Preparing to run MERGE-INTO-C13...
Executing command: bendsql --query=

-- MERGE-INTO-C13: Transaction Counts by User and Asset Type
SELECT user_id, asset_type, COUNT(*) AS count
FROM transactions
GROUP BY user_id, asset_type
ORDER BY count DESC, user_id, asset_type
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
804     ETH     15
1216    ETH     15
216     BTC     14
425     ETH     14
844     BTC     14
1231    ETH     14
1539    ETH     14
1603    ETH     14
1926    ETH     14
2609    BTC     14
2704    ETH     14
2827    ETH     14
2841    BTC     14

Executing command: snowsql --query 

-- MERGE-INTO-C13: Transaction Counts by User and Asset Type
SELECT user_id, asset_type, COUNT(*) AS count
FROM transactions
GROUP BY user_id, asset_type
ORDER BY count DESC, user_id, asset_type
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
804     ETH     15
1216    ETH     15
216     BTC     14
425     ETH     14
844     BTC     14
1231    ETH     14
1539    ETH     14
1603    ETH     14
1926    ETH     14
2609    BTC     14
2704    ETH     14
2827    ETH     14
2841    BTC     14

OK - MERGE-INTO-C13
804     ETH     15
1216    ETH     15
216     BTC     14
425     ETH     14
844     BTC     14
1231    ETH     14
1539    ETH     14
1603    ETH     14
1926    ETH     14
2609    BTC     14
2704    ETH     14
2827    ETH     14
2841    BTC     14

Preparing to run MERGE-INTO-C14...
Executing command: bendsql --query=

-- MERGE-INTO-C14: Date Range Analysis of Transactions
SELECT CASE
           WHEN transaction_time < '2022-01-01' THEN 'Before 2022'
           ELSE 'After 2021-12-31'
           END AS date_range,
       COUNT(*) AS count
FROM transactions
GROUP BY date_range
ORDER BY date_range
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
After 2021-12-31        483526
Before 2022     75015

Executing command: snowsql --query 

-- MERGE-INTO-C14: Date Range Analysis of Transactions
SELECT CASE
           WHEN transaction_time < '2022-01-01' THEN 'Before 2022'
           ELSE 'After 2021-12-31'
           END AS date_range,
       COUNT(*) AS count
FROM transactions
GROUP BY date_range
ORDER BY date_range
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
After 2021-12-31        483526
Before 2022     75015

OK - MERGE-INTO-C14
After 2021-12-31        483526
Before 2022     75015

Preparing to run MERGE-INTO-C15...
Executing command: bendsql --query=

-- MERGE-INTO-C15: asserts
SELECT asset_type, SUM(quantity) AS total_quantity, SUM(value) AS total_value
FROM assets
GROUP BY asset_type ORDER BY asset_type ASC -D mergeinto
Command executed successfully. Output:
BTC     54537998.34092175       545379983.40921303
ETH     50387362.73309448       503873627.33094612
NEW_ASSET       15000000.00000000       150000000.00000000
XRP     45417364.13539917       454173641.35398327

Executing command: snowsql --query 

-- MERGE-INTO-C15: asserts
SELECT asset_type, SUM(quantity) AS total_quantity, SUM(value) AS total_value
FROM assets
GROUP BY asset_type ORDER BY asset_type ASC --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
BTC     54537998.34092175       545379983.40921303
ETH     50387362.73309448       503873627.33094612
NEW_ASSET       15000000.00000000       150000000.00000000
XRP     45417364.13539917       454173641.35398327

OK - MERGE-INTO-C15
BTC     54537998.34092175       545379983.40921303
ETH     50387362.73309448       503873627.33094612
NEW_ASSET       15000000.00000000       150000000.00000000
XRP     45417364.13539917       454173641.35398327

Preparing to run MERGE-INTO-C16...
Executing command: bendsql --query=

-- MERGE-INTO-C16: orders
SELECT asset_type, SUM(quantity) AS total_quantity, AVG(price) AS average_price
FROM orders
GROUP BY asset_type ORDER BY asset_type ASC -D mergeinto
Command executed successfully. Output:
BTC     577143846.60937705      1321.552983291813
ETH     532400471.20223598      1228.552050777431
NEW_ORDER       7500000.00000000        500.000000000000
XRP     409811224.65137297      1172.281276438386

Executing command: snowsql --query 

-- MERGE-INTO-C16: orders
SELECT asset_type, SUM(quantity) AS total_quantity, AVG(price) AS average_price
FROM orders
GROUP BY asset_type ORDER BY asset_type ASC --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
BTC     577143846.60937705      1321.552983291813
ETH     532400471.20223598      1228.552050777431
NEW_ORDER       7500000.00000000        500.000000000000
XRP     409811224.65137297      1172.281276438386

OK - MERGE-INTO-C16
BTC     577143846.60937705      1321.552983291813
ETH     532400471.20223598      1228.552050777431
NEW_ORDER       7500000.00000000        500.000000000000
XRP     409811224.65137297      1172.281276438386

Preparing to run MERGE-INTO-C17...
Executing command: bendsql --query=

-- MERGE-INTO-C17: transactions
SELECT transaction_type, SUM(quantity) AS total_quantity
FROM transactions
GROUP BY transaction_type ORDER BY transaction_type ASC -D mergeinto
Command executed successfully. Output:
deposit 5712183.27889012
trade   62705473.53457811
withdrawal      5209604.75951623

Executing command: snowsql --query 

-- MERGE-INTO-C17: transactions
SELECT transaction_type, SUM(quantity) AS total_quantity
FROM transactions
GROUP BY transaction_type ORDER BY transaction_type ASC --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
deposit 5712183.27889012
trade   62705473.53457811
withdrawal      5209604.75951623

OK - MERGE-INTO-C17
deposit 5712183.27889012
trade   62705473.53457811
withdrawal      5209604.75951623

@JackTan25
Copy link
Contributor Author

JackTan25 commented Jan 4, 2024

standalone mode passed in wizard:

Click me
Preparing to run MERGE-INTO-C1...
Executing command: bendsql --query=-- MERGE-INTO-C1: Asset Types Distribution
SELECT asset_type, COUNT(*) AS count
FROM assets
GROUP BY asset_type
ORDER BY count DESC, asset_type
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
NEW_ASSET       150000
BTC     104817
ETH     104808
XRP     90375

Executing command: snowsql --query -- MERGE-INTO-C1: Asset Types Distribution
SELECT asset_type, COUNT(*) AS count
FROM assets
GROUP BY asset_type
ORDER BY count DESC, asset_type
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
NEW_ASSET       150000
BTC     104817
ETH     104808
XRP     90375

OK - MERGE-INTO-C1
NEW_ASSET       150000
BTC     104817
ETH     104808
XRP     90375

Preparing to run MERGE-INTO-C2...
Executing command: bendsql --query=

-- MERGE-INTO-C2: Aggregated Quantity and Value Statistics
SELECT SUM(quantity) AS total_quantity,
       AVG(quantity) AS average_quantity,
       SUM(value) AS total_value,
       AVG(value) AS average_value
FROM assets -D mergeinto
Command executed successfully. Output:
165342725.20941540      367.428278243145        1653427252.09414242     3674.282782431428

Executing command: snowsql --query 

-- MERGE-INTO-C2: Aggregated Quantity and Value Statistics
SELECT SUM(quantity) AS total_quantity,
       AVG(quantity) AS average_quantity,
       SUM(value) AS total_value,
       AVG(value) AS average_value
FROM assets --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
165342725.20941540      367.428278243145        1653427252.09414242     3674.282782431428

OK - MERGE-INTO-C2
165342725.20941540      367.428278243145        1653427252.09414242     3674.282782431428

Preparing to run MERGE-INTO-C3...
Executing command: bendsql --query=

-- MERGE-INTO-C3: Assets Counts by User
SELECT user_id, COUNT(*) AS count
FROM assets
GROUP BY user_id
ORDER BY count DESC, user_id
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
0       6
2       6
4       6
6       6
8       6
10      6
12      6
14      6
16      6
18      6
20      6
22      6
24      6

Executing command: snowsql --query 

-- MERGE-INTO-C3: Assets Counts by User
SELECT user_id, COUNT(*) AS count
FROM assets
GROUP BY user_id
ORDER BY count DESC, user_id
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
0       6
2       6
4       6
6       6
8       6
10      6
12      6
14      6
16      6
18      6
20      6
22      6
24      6

OK - MERGE-INTO-C3
0       6
2       6
4       6
6       6
8       6
10      6
12      6
14      6
16      6
18      6
20      6
22      6
24      6

Preparing to run MERGE-INTO-C4...
Executing command: bendsql --query=

-- MERGE-INTO-C4: Date Range Analysis of Last Update
SELECT CASE
           WHEN last_updated < '2022-01-01' THEN 'Before 2022'
           ELSE 'After 2021-12-31'
           END AS date_range,
       COUNT(*) AS count
FROM assets
GROUP BY date_range
ORDER BY date_range
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
After 2021-12-31        410014
Before 2022     39986

Executing command: snowsql --query 

-- MERGE-INTO-C4: Date Range Analysis of Last Update
SELECT CASE
           WHEN last_updated < '2022-01-01' THEN 'Before 2022'
           ELSE 'After 2021-12-31'
           END AS date_range,
       COUNT(*) AS count
FROM assets
GROUP BY date_range
ORDER BY date_range
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
After 2021-12-31        410014
Before 2022     39986

OK - MERGE-INTO-C4
After 2021-12-31        410014
Before 2022     39986

Preparing to run MERGE-INTO-C5...
Executing command: bendsql --query=

-- MERGE-INTO-C5: General Status Distribution
SELECT status, COUNT(*) AS count
FROM orders
GROUP BY status
ORDER BY count DESC, status
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
avg     1049532
completed       350986
pending 348300
cancelled       300714
Pending 150000
above_avg       100418
below_avg       100075

Executing command: snowsql --query 

-- MERGE-INTO-C5: General Status Distribution
SELECT status, COUNT(*) AS count
FROM orders
GROUP BY status
ORDER BY count DESC, status
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
avg     1049532
completed       350986
pending 348300
cancelled       300714
Pending 150000
above_avg       100418
below_avg       100075

OK - MERGE-INTO-C5
avg     1049532
completed       350986
pending 348300
cancelled       300714
Pending 150000
above_avg       100418
below_avg       100075

Preparing to run MERGE-INTO-C6...
Executing command: bendsql --query=

-- MERGE-INTO-C6: General Quantity Statistics
SELECT SUM(quantity) AS total_quantity,
       AVG(quantity) AS average_quantity,
       MIN(quantity) AS min_quantity,
       MAX(quantity) AS max_quantity
FROM orders -D mergeinto
Command executed successfully. Output:
1526855542.46298600     636.183182451427        0.00005807      8910.78518320

Executing command: snowsql --query 

-- MERGE-INTO-C6: General Quantity Statistics
SELECT SUM(quantity) AS total_quantity,
       AVG(quantity) AS average_quantity,
       MIN(quantity) AS min_quantity,
       MAX(quantity) AS max_quantity
FROM orders --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
1526855542.46298600     636.183182451427        0.00005807      8910.78518320

OK - MERGE-INTO-C6
1526855542.46298600     636.183182451427        0.00005807      8910.78518320

Preparing to run MERGE-INTO-C7...
Executing command: bendsql --query=

-- MERGE-INTO-C7: New Orders vs Existing Orders Count
SELECT CASE
           WHEN order_id > 500000 THEN 'New Order'
           ELSE 'Existing Order'
           END AS order_category,
       COUNT(*) AS count
FROM orders
GROUP BY order_category
ORDER BY count DESC
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
New Order       1649995
Existing Order  750030

Executing command: snowsql --query 

-- MERGE-INTO-C7: New Orders vs Existing Orders Count
SELECT CASE
           WHEN order_id > 500000 THEN 'New Order'
           ELSE 'Existing Order'
           END AS order_category,
       COUNT(*) AS count
FROM orders
GROUP BY order_category
ORDER BY count DESC
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
New Order       1649995
Existing Order  750030

OK - MERGE-INTO-C7
New Order       1649995
Existing Order  750030

Preparing to run MERGE-INTO-C8...
Executing command: bendsql --query=

-- MERGE-INTO-C8: Order Type Distribution
SELECT order_type, COUNT(*) AS count
FROM orders
GROUP BY order_type
ORDER BY count DESC, order_type
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
buy     1274986
sell    1125039

Executing command: snowsql --query 

-- MERGE-INTO-C8: Order Type Distribution
SELECT order_type, COUNT(*) AS count
FROM orders
GROUP BY order_type
ORDER BY count DESC, order_type
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
buy     1274986
sell    1125039

OK - MERGE-INTO-C8
buy     1274986
sell    1125039

Preparing to run MERGE-INTO-C9...
Executing command: bendsql --query=

-- MERGE-INTO-C9: Date Range Analysis
SELECT CASE
           WHEN created_at < '2022-01-01' THEN 'Before 2022'
           WHEN created_at BETWEEN '2021-01-01' AND '2021-06-30' THEN 'First Half 2021'
           ELSE 'After 2021-06-30'
           END AS date_range,
       COUNT(*) AS count
FROM orders
GROUP BY date_range
ORDER BY date_range
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
After 2021-06-30        150000
Before 2022     2250025

Executing command: snowsql --query 

-- MERGE-INTO-C9: Date Range Analysis
SELECT CASE
           WHEN created_at < '2022-01-01' THEN 'Before 2022'
           WHEN created_at BETWEEN '2021-01-01' AND '2021-06-30' THEN 'First Half 2021'
           ELSE 'After 2021-06-30'
           END AS date_range,
       COUNT(*) AS count
FROM orders
GROUP BY date_range
ORDER BY date_range
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
After 2021-06-30        150000
Before 2022     2250025

OK - MERGE-INTO-C9
After 2021-06-30        150000
Before 2022     2250025

Preparing to run MERGE-INTO-C10...
Executing command: bendsql --query=

-- MERGE-INTO-C10: Price Analysis After Adjustments
SELECT SUM(price) AS total_price,
       AVG(price) AS average_price,
       MIN(price) AS min_price,
       MAX(price) AS max_price
FROM orders -D mergeinto
Command executed successfully. Output:
2874615680.22030825     1197.744056924535       0.00058074      10990.07262787

Executing command: snowsql --query 

-- MERGE-INTO-C10: Price Analysis After Adjustments
SELECT SUM(price) AS total_price,
       AVG(price) AS average_price,
       MIN(price) AS min_price,
       MAX(price) AS max_price
FROM orders --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
2874615680.22030825     1197.744056924535       0.00058074      10990.07262787

OK - MERGE-INTO-C10
2874615680.22030825     1197.744056924535       0.00058074      10990.07262787

Preparing to run MERGE-INTO-C11...
Executing command: bendsql --query=

-- MERGE-INTO-C11: Transaction Types Distribution
SELECT transaction_type, COUNT(*) AS count
FROM transactions
GROUP BY transaction_type
ORDER BY count DESC, transaction_type
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
trade   505920
deposit 26492
withdrawal      26129

Executing command: snowsql --query 

-- MERGE-INTO-C11: Transaction Types Distribution
SELECT transaction_type, COUNT(*) AS count
FROM transactions
GROUP BY transaction_type
ORDER BY count DESC, transaction_type
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
trade   505920
deposit 26492
withdrawal      26129

OK - MERGE-INTO-C11
trade   505920
deposit 26492
withdrawal      26129

Preparing to run MERGE-INTO-C12...
Executing command: bendsql --query=

-- MERGE-INTO-C12: Aggregated Quantity Statistics
SELECT SUM(quantity) AS total_quantity,
       AVG(quantity) AS average_quantity,
       MIN(quantity) AS min_quantity,
       MAX(quantity) AS max_quantity
FROM transactions -D mergeinto
Command executed successfully. Output:
73627261.57298446       131.820692792444        0.00106899      664.06985910

Executing command: snowsql --query 

-- MERGE-INTO-C12: Aggregated Quantity Statistics
SELECT SUM(quantity) AS total_quantity,
       AVG(quantity) AS average_quantity,
       MIN(quantity) AS min_quantity,
       MAX(quantity) AS max_quantity
FROM transactions --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
73627261.57298446       131.820692792444        0.00106899      664.06985910

OK - MERGE-INTO-C12
73627261.57298446       131.820692792444        0.00106899      664.06985910

Preparing to run MERGE-INTO-C13...
Executing command: bendsql --query=

-- MERGE-INTO-C13: Transaction Counts by User and Asset Type
SELECT user_id, asset_type, COUNT(*) AS count
FROM transactions
GROUP BY user_id, asset_type
ORDER BY count DESC, user_id, asset_type
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
804     ETH     15
1216    ETH     15
216     BTC     14
425     ETH     14
844     BTC     14
1231    ETH     14
1539    ETH     14
1603    ETH     14
1926    ETH     14
2609    BTC     14
2704    ETH     14
2827    ETH     14
2841    BTC     14

Executing command: snowsql --query 

-- MERGE-INTO-C13: Transaction Counts by User and Asset Type
SELECT user_id, asset_type, COUNT(*) AS count
FROM transactions
GROUP BY user_id, asset_type
ORDER BY count DESC, user_id, asset_type
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
804     ETH     15
1216    ETH     15
216     BTC     14
425     ETH     14
844     BTC     14
1231    ETH     14
1539    ETH     14
1603    ETH     14
1926    ETH     14
2609    BTC     14
2704    ETH     14
2827    ETH     14
2841    BTC     14

OK - MERGE-INTO-C13
804     ETH     15
1216    ETH     15
216     BTC     14
425     ETH     14
844     BTC     14
1231    ETH     14
1539    ETH     14
1603    ETH     14
1926    ETH     14
2609    BTC     14
2704    ETH     14
2827    ETH     14
2841    BTC     14

Preparing to run MERGE-INTO-C14...
Executing command: bendsql --query=

-- MERGE-INTO-C14: Date Range Analysis of Transactions
SELECT CASE
           WHEN transaction_time < '2022-01-01' THEN 'Before 2022'
           ELSE 'After 2021-12-31'
           END AS date_range,
       COUNT(*) AS count
FROM transactions
GROUP BY date_range
ORDER BY date_range
    LIMIT 13 -D mergeinto
Command executed successfully. Output:
After 2021-12-31        483526
Before 2022     75015

Executing command: snowsql --query 

-- MERGE-INTO-C14: Date Range Analysis of Transactions
SELECT CASE
           WHEN transaction_time < '2022-01-01' THEN 'Before 2022'
           ELSE 'After 2021-12-31'
           END AS date_range,
       COUNT(*) AS count
FROM transactions
GROUP BY date_range
ORDER BY date_range
    LIMIT 13 --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
After 2021-12-31        483526
Before 2022     75015

OK - MERGE-INTO-C14
After 2021-12-31        483526
Before 2022     75015

Preparing to run MERGE-INTO-C15...
Executing command: bendsql --query=

-- MERGE-INTO-C15: asserts
SELECT asset_type, SUM(quantity) AS total_quantity, SUM(value) AS total_value
FROM assets
GROUP BY asset_type ORDER BY asset_type ASC -D mergeinto
Command executed successfully. Output:
BTC     54537998.34092175       545379983.40921303
ETH     50387362.73309448       503873627.33094612
NEW_ASSET       15000000.00000000       150000000.00000000
XRP     45417364.13539917       454173641.35398327

Executing command: snowsql --query 

-- MERGE-INTO-C15: asserts
SELECT asset_type, SUM(quantity) AS total_quantity, SUM(value) AS total_value
FROM assets
GROUP BY asset_type ORDER BY asset_type ASC --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
BTC     54537998.34092175       545379983.40921303
ETH     50387362.73309448       503873627.33094612
NEW_ASSET       15000000.00000000       150000000.00000000
XRP     45417364.13539917       454173641.35398327

OK - MERGE-INTO-C15
BTC     54537998.34092175       545379983.40921303
ETH     50387362.73309448       503873627.33094612
NEW_ASSET       15000000.00000000       150000000.00000000
XRP     45417364.13539917       454173641.35398327

Preparing to run MERGE-INTO-C16...
Executing command: bendsql --query=

-- MERGE-INTO-C16: orders
SELECT asset_type, SUM(quantity) AS total_quantity, AVG(price) AS average_price
FROM orders
GROUP BY asset_type ORDER BY asset_type ASC -D mergeinto
Command executed successfully. Output:
BTC     577143846.60937705      1321.552983291813
ETH     532400471.20223598      1228.552050777431
NEW_ORDER       7500000.00000000        500.000000000000
XRP     409811224.65137297      1172.281276438386

Executing command: snowsql --query 

-- MERGE-INTO-C16: orders
SELECT asset_type, SUM(quantity) AS total_quantity, AVG(price) AS average_price
FROM orders
GROUP BY asset_type ORDER BY asset_type ASC --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
BTC     577143846.60937705      1321.552983291813
ETH     532400471.20223598      1228.552050777431
NEW_ORDER       7500000.00000000        500.000000000000
XRP     409811224.65137297      1172.281276438386

OK - MERGE-INTO-C16
BTC     577143846.60937705      1321.552983291813
ETH     532400471.20223598      1228.552050777431
NEW_ORDER       7500000.00000000        500.000000000000
XRP     409811224.65137297      1172.281276438386

Preparing to run MERGE-INTO-C17...
Executing command: bendsql --query=

-- MERGE-INTO-C17: transactions
SELECT transaction_type, SUM(quantity) AS total_quantity
FROM transactions
GROUP BY transaction_type ORDER BY transaction_type ASC -D mergeinto
Command executed successfully. Output:
deposit 5712183.27889012
trade   62705473.53457811
withdrawal      5209604.75951623

Executing command: snowsql --query 

-- MERGE-INTO-C17: transactions
SELECT transaction_type, SUM(quantity) AS total_quantity
FROM transactions
GROUP BY transaction_type ORDER BY transaction_type ASC --dbname mergeinto --schemaname PUBLIC -o output_format=tsv -o header=false -o timing=false -o friendly=false --warehouse COMPUTE_WH
Command executed successfully. Output:
deposit 5712183.27889012
trade   62705473.53457811
withdrawal      5209604.75951623

OK - MERGE-INTO-C17
deposit 5712183.27889012
trade   62705473.53457811
withdrawal      5209604.75951623

@JackTan25 JackTan25 marked this pull request as ready for review January 4, 2024 05:12
@dantengsky dantengsky added this pull request to the merge queue Jan 4, 2024
Merged via the queue into databendlabs:main with commit 8ba2c12 Jan 4, 2024
71 checks passed
JackTan25 added a commit that referenced this pull request Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-cloud Build docker image for cloud test pr-chore this PR only has small changes that no need to record, like coding styles.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants