Currently the exact size of a cached entry is not used when limiting the amount of memory used by the query classifier cache. This may lead to the cache using more memory than what it is supposed to use.
Further, when fields and functions are collected, separate strings are allocated for those. They should be stored as std::string_view:s pointing into the canonical statement. That would significantly reduce the amount of memory per query classifier cache entry.