Comments - COUNT DISTINCT
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.
Question: Is COUNT DISTINCT optimized to take advantage of sorted values?
For example, if I have a sorted column
LAST_NAME, thenSELECT COUNT(DISTINCT(LAST_NAME)) FROM PEOPLEcan be performed in a constant amount of memory: if you iterate the rows inLAST_NAMEorder, then you're guaranteed that all distinct last name values appear contiguously, so there's no need to remember which one's you've already seen.