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

feat: change tracking enabled table support replace into #14831

Merged
merged 4 commits into from Mar 5, 2024

Conversation

zhyass
Copy link
Member

@zhyass zhyass commented Mar 4, 2024

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

Summary

mysql> create table t(a int);
Query OK, 0 rows affected (0.12 sec)

mysql> insert into t values(1),(2);
Query OK, 2 rows affected (0.22 sec)

mysql> create stream s on table t append_only=false;
Query OK, 0 rows affected (0.13 sec)

mysql> replace into t on(a) values(2),(3);
Query OK, 3 rows affected (0.50 sec)

mysql> select * from s;
+------+---------------+----------------------------------------+------------------+
| a    | change$action | change$row_id                          | change$is_update |
+------+---------------+----------------------------------------+------------------+
|    2 | DELETE        | 84cabcdbe670450c9f0a260a225757ab000001 |                0 |
|    2 | INSERT        | 21550750d91b41298560db28862fc7e1000000 |                0 |
|    3 | INSERT        | 21550750d91b41298560db28862fc7e1000001 |                0 |
+------+---------------+----------------------------------------+------------------+
3 rows in set (0.25 sec)
Read 5 rows, 312.00 B in 0.072 sec., 69.29 rows/sec., 4.22 KiB/sec.
  • Fixes #[Link the issue here]

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

@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Mar 4, 2024
@zhyass zhyass changed the title feat: change enabled table support replace into feat: change tracking enabled table support replace into Mar 4, 2024
@dantengsky
Copy link
Member

dantengsky commented Mar 5, 2024

for append only stream, the "semantic" appears to be inconsistent:

Given table t, insert row r, and then create a stream s based on t:

  • after updating row r, s captures nothing
  • but, if replacing into row r, one row is captured

mysql >  --- after replace into, one row captured
mysql> create table t (id int, v string);
Query OK, 0 rows affected (1.48 sec)

mysql> insert into t values(1, 'a');
Query OK, 1 row affected (0.25 sec)

mysql> create stream s on table t append_only = true;
Query OK, 0 rows affected (0.35 sec)

mysql> replace into t on(id) values(1, 'b');
Query OK, 2 rows affected (0.51 sec)

mysql> select * from s;
+------+------+---------------+------------------+----------------------------------------+
| id   | v    | change$action | change$is_update | change$row_id                          |
+------+------+---------------+------------------+----------------------------------------+
|    1 | b    | INSERT        |                0 | fcaad8936ed043a6b0c5e02873e91d48000000 |
+------+------+---------------+------------------+----------------------------------------+
1 row in set (0.37 sec)
Read 1 rows, 215.00 B in 0.177 sec., 5.65 rows/sec., 1.19 KiB/sec.

mysql> --- after updating, no rows captured

mysql> create table t1 (id int, v string);
Query OK, 0 rows affected (0.09 sec)

mysql> insert into t1 values(1, 'a');
Query OK, 1 row affected (0.11 sec)

mysql> create stream s1 on table t1 append_only = true;
Query OK, 0 rows affected (0.11 sec)

mysql> update  t1 set v = 'b' where id = 1;
Query OK, 1 row affected (0.56 sec)

mysql> select * from s1;
Empty set (0.27 sec)
Read 1 rows, 58.00 B in 0.061 sec., 16.49 rows/sec., 956.18 B/sec.

mysql> select version();
+----------------------------------------------------------------------------------------+
| version()                                                                              |
+----------------------------------------------------------------------------------------+
| 8.0.26-v1.2.360-nightly-096a909d91(rust-1.77.0-nightly-2024-03-05T08:56:26.362694196Z) |
+----------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
Read 1 rows, 1.00 B in 0.004 sec., 256.96 rows/sec., 256.96 B/sec.

is this intended behavior?

@zhyass
Copy link
Member Author

zhyass commented Mar 5, 2024

captured

Yes, it's intended behavior. Here treat the semantics of replace as INSERT and DELETE, not INSERT and UPDATE. Take the following sql as an example.

mysql> create table t(a int, b string);
Query OK, 0 rows affected (0.03 sec)

mysql> insert into t values(1,'a'),(1,'b'),(2,'b');
Query OK, 3 rows affected (0.04 sec)

mysql> replace into t on(a) values(1,'a1'),(3,'c');
Query OK, 4 rows affected (0.11 sec)

mysql> select * from t order by a;
+------+------+
| a    | b    |
+------+------+
|    1 | a1   |
|    2 | b    |
|    3 | c    |
+------+------+
3 rows in set (0.04 sec)
Read 3 rows, 50.00 B in 0.020 sec., 146.61 rows/sec., 2.39 KiB/sec.

We can make a note in the documentation to remind users of this distinction.

@dantengsky
Copy link
Member

treat the semantics of replace as INSERT and DELETE, not INSERT and UPDATE
....
We can make a note in the documentation to remind users of this distinction.

looks reasonable to me, let's roll out.

@dantengsky dantengsky added this pull request to the merge queue Mar 5, 2024
@BohuTANG BohuTANG removed this pull request from the merge queue due to a manual request Mar 5, 2024
@BohuTANG BohuTANG merged commit 4f2e1d0 into datafuselabs:main Mar 5, 2024
71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants