メインコンテンツまでスキップ

approx_count_distinct

APPROX_COUNT_DISTINCT

説明

COUNT(DISTINCT col)の結果に類似した集計関数の近似値を返します。

COUNTとDISTINCTの組み合わせよりも高速であり、固定サイズのメモリを使用するため、高基数の列に対してメモリ使用量が少なくなります。

構文

APPROX_COUNT_DISTINCT(expr)

MySQL > select approx_count_distinct(query_id) from log_statis group by datetime;
+-----------------------------------+
| approx_count_distinct(`query_id`) |
+-----------------------------------+
| 17721 |
+-----------------------------------+

キーワード

APPROX_COUNT_DISTINCT