Describe the bug
ALTER TABLE ontime MODIFY TTL doesn't work, the outdated data is not deleted
How to reproduce
version: 19.8.3.8.
CREATE TABLE statements for all tables involvedCREATE TABLE
ontime(\
YearUInt16,\
QuarterUInt8,\
MonthUInt8,\
DayofMonthUInt8,\
DayOfWeekUInt8,\
FlightDate Date,\
UniqueCarrierFixedString(7),\
AirlineIDInt32,\
CarrierFixedString(2),\
TailNumString,\
FlightNumString,\
OriginAirportIDInt32,\
OriginAirportSeqIDInt32,\
OriginCityMarketIDInt32,\
OriginFixedString(5),\
OriginCityNameString,\
OriginStateFixedString(2),\
OriginStateFipsString,\
OriginStateNameString,\
OriginWacInt32,\
DestAirportIDInt32,\
DestAirportSeqIDInt32,\
DestCityMarketIDInt32,\
DestFixedString(5),\
DestCityNameString,\
DestStateFixedString(2),\
DestStateFipsString,\
DestStateNameString,\
DestWacInt32,\
CRSDepTimeInt32,\
DepTimeInt32,\
DepDelayInt32,\
DepDelayMinutesInt32,\
DepDel15Int32,\
DepartureDelayGroupsString,\
DepTimeBlkString,\
TaxiOutInt32,\
WheelsOffInt32,\
WheelsOnInt32,\
TaxiInInt32,\
CRSArrTimeInt32,\
ArrTimeInt32,\
ArrDelayInt32,\
ArrDelayMinutesInt32,\
ArrDel15Int32,\
ArrivalDelayGroupsInt32,\
ArrTimeBlkString,\
CancelledUInt8,\
CancellationCodeFixedString(1),\
DivertedUInt8,\
CRSElapsedTimeInt32,\
ActualElapsedTimeInt32,\
AirTimeInt32,\
FlightsInt32,\
DistanceInt32,\
DistanceGroupUInt8,\
CarrierDelayInt32,\
WeatherDelayInt32,\
NASDelayInt32,\
SecurityDelayInt32,\
LateAircraftDelayInt32,\
FirstDepTimeString,\
TotalAddGTimeString,\
LongestAddGTimeString,\
DivAirportLandingsString,\
DivReachedDestString,\
DivActualElapsedTimeString,\
DivArrDelayString,\
DivDistanceString,\
Div1AirportString,\
Div1AirportIDInt32,\
Div1AirportSeqIDInt32,\
Div1WheelsOnString,\
Div1TotalGTimeString,\
Div1LongestGTimeString,\
Div1WheelsOffString,\
Div1TailNumString,\
Div2AirportString,\
Div2AirportIDInt32,\
Div2AirportSeqIDInt32,\
Div2WheelsOnString,\
Div2TotalGTimeString,\
Div2LongestGTimeString,\
Div2WheelsOffString,\
Div2TailNumString,\
Div3AirportString,\
Div3AirportIDInt32,\
Div3AirportSeqIDInt32,\
Div3WheelsOnString,\
Div3TotalGTimeString,\
Div3LongestGTimeString,\
Div3WheelsOffString,\
Div3TailNumString,\
Div4AirportString,\
Div4AirportIDInt32,\
Div4AirportSeqIDInt32,\
Div4WheelsOnString,\
Div4TotalGTimeString,\
Div4LongestGTimeString,\
Div4WheelsOffString,\
Div4TailNumString,\
Div5AirportString,\
Div5AirportIDInt32,\
Div5AirportSeqIDInt32,\
Div5WheelsOnString,\
Div5TotalGTimeString,\
Div5LongestGTimeString,\
Div5WheelsOffString,\
Div5TailNumString\
) ENGINE = \
ReplicatedMergeTree('/clickhouse-test/tables/{shard}/ontime', '{replica}') \
PARTITION BY toYYYYMM(FlightDate) \
ORDER BY (Year, Quarter, Month, DayofMonth, DayOfWeek, FlightDate) \
SETTINGS index_granularity = 8192
Expected behavior
select count(*) from ontime
the number of rows reduced
Additional context
The show create table query shows that the ttl is actually modified, so it is not same bug as #5494
When table is created with ttl, after import data into the table, and run the OPTIMIZE query, the number of rows is reduced
Initially TTL was implemented with (maybe a bit confusing) logic, that parts created before ALTER TABLE ... MODIFY TTL would never be dropped by TTL. It was changed in PR #6274 and now those old parts can be filtered by TTL with OPTIMIZE ... FINAL query. This patch will be available in 19.14 release.
NOTE: Even now extra merges with TTL won't assign automatically for parts, created before ALTER query. That data can be deleted only manually with OPTIMIZE ... FINAL query.
@CurtizJ I think the new ttl behavior is still not good enough and is still confusing. It's better to purge out-dated data automatically. Maybe a new background scanner thread to scan parts to do the purge periodically. A part should have statistics about min/max value of a Date/Datetime column, so the scanner should not cost lots of resources to do the scan
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Initially TTL was implemented with (maybe a bit confusing) logic, that parts created before
ALTER TABLE ... MODIFY TTLwould never be dropped by TTL. It was changed in PR #6274 and now those old parts can be filtered by TTL withOPTIMIZE ... FINALquery. This patch will be available in 19.14 release.NOTE: Even now extra merges with TTL won't assign automatically for parts, created before
ALTERquery. That data can be deleted only manually withOPTIMIZE ... FINALquery.