databend
databend copied to clipboard
Feature: Target Build Optimization for native engine.
Summary In Pr https://github.com/datafuselabs/databend/pull/14066, we support block info hash table optimization for merge into. But in fact, it doesn't native engine. for now, we disable target_table_optimization for native. Native will,spilt one block into multi pages. We should fix this one in the future.
statement ok
CREATE TABLE orders CLUSTER BY (to_yyyymmddhh(created_at), user_id) AS SELECT
number % 5000 AS order_id,
number % 10000 AS user_id,
CASE WHEN (rand() * 10)::int % 2 = 0 THEN 'buy'
ELSE 'sell'
END AS order_type,
CASE WHEN (rand() * 10)::int % 3 = 0 THEN 'BTC'
WHEN (rand() * 10)::int % 3 = 1 THEN 'ETH'
ELSE 'XRP'
END AS asset_type,
(rand() * 100)::decimal(18, 8) AS quantity,
(rand() * 1000)::decimal(18, 8) AS price,
CASE WHEN (rand() * 10)::int % 3 = 0 THEN 'completed'
WHEN (rand() * 10)::int % 3 = 1 THEN 'pending'
ELSE 'cancelled'
END AS status,
date_add('day', floor(rand() * 10 % 365)::int, '2021-01-01') AS created_at,
date_add('day', floor(rand() * 10 % 365)::int, '2021-01-01') AS updated_at
FROM numbers(5000);
statement ok
MERGE INTO orders USING
(
SELECT
number % 5000 AS order_id,
number % 100000 AS user_id,
CASE WHEN (rand() * 10)::int % 2 = 0 THEN 'buy'
ELSE 'sell'
END AS order_type,
CASE WHEN (rand() * 10)::int % 3 = 0 THEN 'BTC'
WHEN (rand() * 10)::int % 3 = 1 THEN 'ETH'
ELSE 'XRP'
END AS asset_type,
(rand() * 100)::decimal(18, 8) AS quantity,
(rand() * 1000)::decimal(18, 8) AS price,
CASE WHEN (rand() * 10)::int % 3 = 0 THEN 'completed'
WHEN (rand() * 10)::int % 3 = 1 THEN 'pending'
ELSE 'cancelled'
END AS status,
date_add('day', floor(rand() * 10 % 365)::int, '2021-01-01') AS created_at,
date_add('day', floor(rand() * 10 % 365)::int, '2021-01-01') AS updated_at
FROM numbers(5000)
) AS source
ON orders.order_id = source.order_id
WHEN MATCHED THEN
UPDATE SET
orders.user_id = source.user_id,
orders.order_type = source.order_type,
orders.asset_type = source.asset_type,
orders.quantity = source.quantity,
orders.price = source.price,
orders.status = source.status,
orders.created_at = source.created_at,
orders.updated_at = source.updated_at
WHEN NOT MATCHED THEN
INSERT (order_id, user_id, order_type, asset_type, quantity, price, status, created_at, updated_at)
VALUES (source.order_id, source.user_id, source.order_type, source.asset_type, source.quantity, source.price, source.status, source.created_at, source.updated_at);