timeplus-io / proton

A stream processing engine and database, and a fast and lightweight alternative to ksqlDB and Apache Flink, 🚀 powered by ClickHouse
https://timeplus.com
Apache License 2.0
1.58k stars 70 forks source link

`TRUNCATE` unable to delete data in logstore #115

Open leo-cai-timeplus opened 1 year ago

leo-cai-timeplus commented 1 year ago

Describe what's wrong

create stream a(i int);
insert into a (i) values (1);
truncate stream a;

after that, run select * from table(a) and you will get nothing,

but run select i from a where _tp_time>earliest_ts() limit 1 and the result will be

┌─i─┐
│ 1 │
└───┘

How to reproduce

run

create stream a(i int);
insert into a (i) values (1);
truncate stream a;
select * from table(a);
select i from a where _tp_time>earliest_ts() limit 1;

Error message and/or stacktrace

d483020dcef5 :) create stream a(i int);
                insert into a (i) values (1);

CREATE STREAM a
(`i` int
)

Query id: fd2546bc-21c5-47dc-b4c6-78401d7a5cdb

Ok.

0 rows in set. Elapsed: 0.030 sec. 

INSERT INTO a (i) FORMAT Values

Query id: 8894f3f3-c6d4-4261-869e-f70d7676e58c

Ok.

1 rows in set. Elapsed: 0.006 sec. 

d483020dcef5 :) truncate stream a;

TRUNCATE STREAM a

Query id: 8d8c84dd-4774-4f78-af82-082b788b947c

Ok.

0 rows in set. Elapsed: 0.002 sec.

d483020dcef5 :) select * from table(a)

SELECT 
  *
FROM 
  table(a)

Query id: ed223e9e-26a3-4d2e-be3d-c743304186fa

Ok.

0 rows in set. Elapsed: 0.002 sec. 

d483020dcef5 :) select i from a where _tp_time>earliest_ts() limit 1

SELECT 
  i
FROM 
  a
WHERE 
  _tp_time > earliest_ts()
LIMIT 1

Query id: 0b92e846-b182-4c64-a253-79498c991eb0

┌─i─┐
│ 1 │
└───┘

1 rows in set. Elapsed: 0.003 sec. 

Additional context

leo-cai-timeplus commented 1 year ago

if we run

create stream a(i int);
insert into a (i) values (1);
insert into a (i) values (2);
insert into a (i) values (3);
truncate stream a;

in multiquery mode,

then we run select * from table(a) and the result will be

d483020dcef5 :) select * from table(a)

SELECT 
  *
FROM 
  table(a)

Query id: 6f562454-2eef-4ee5-b2ca-ef640bce1be9

┌─i─┬────────────────_tp_time─┐
│ 1 │ 2023-09-20 02:52:51.267 │
│ 2 │ 2023-09-20 02:52:51.270 │
│ 3 │ 2023-09-20 02:52:51.272 │
└───┴─────────────────────────┘

3 rows in set. Elapsed: 0.003 sec. 

if we run

create stream a(i int);
insert into a (i) values (1);
insert into a (i) values (2);
insert into a (i) values (3);

and then run

truncate stream a;

then we run select * from table(a) and the result will be empty.