Statistics: why old sensors deleted long time ago are still present in DB?

Some time ago I noticed that long-term statistics keeps data for deleted sensors:

  • a sensor with “state_class: measurement” is created;
  • statistics is stored for the sensor;
  • the sensor is deleted;
  • but statistics still present in DB - and is not purged after some time.

Surely this behaviour may be useful:

  • there is some useful sensor;
  • statistics is stored for this sensor;
  • then this sensor was deleted TEMPORARILY (or the whole integration was removed);
  • then the sensor was re-added again;
  • and voilà - whole statistics for this sensor is still available.

But in many (most?) cases deleted sensors are not restored - and data are still present in DB.
And there is no any tool to delete these old data from DB (“dev tools → statistics”).