данные интерпретирую, то ли что-то еще.
в таблице есть 17.85 миллионов строк.
есть индекс
INDEX number_index_minmax plate_number TYPE minmax GRANULARITY 128
ORDER BY ("datetime", "origin_id", "origin_event_uuid")
делаю explain:
EXPLAIN indexes = 1 SELECT count() AS count FROM test_numbers_3 WHERE plate_number = '670HWA09'
┌─explain─────────────────────────────────────────────────────────────────────────┐
│ Expression ((Projection + Before ORDER BY)) │
│ Aggregating │
│ Expression (Before GROUP BY) │
│ Filter (WHERE) │
│ SettingQuotaAndLimits (Set limits and quota after reading from storage) │
│ ReadFromMergeTree │
│ Indexes: │
│ MinMax │
│ Condition: true │
│ Parts: 36/36 │
│ Granules: 17447/17447 │
│ Partition │
│ Condition: true │
│ Parts: 36/36 │
│ Granules: 17447/17447 │
│ PrimaryKey │
│ Condition: true │
│ Parts: 36/36 │
│ Granules: 17447/17447 │
│ Skip │
│ Name: number_index_minmax │
│ Description: minmax GRANULARITY 128 │
│ Parts: 32/36 │
│ Granules: 147/17447 │
└─────────────────────────────────────────────────────────────────────────────────┘
Вроде бы Granules: 147/17447 в индексе number_index_minmax означает, что должен прочитать меньше строк, верно?
Но
SELECT count() AS count FROM test_numbers_3 WHERE plate_number = '670HWA09'
┌─count─┐
│ 92 │
└───────┘
1 rows in set. Elapsed: 0.094 sec. Processed 17.85 million rows, 299.43 MB (189.30 million rows/s., 3.18 GB/s.)
Последняя строка Processed 17.85 million rows ведь означает, что все равно были прочитаны все 17,85 миллионов. Почему так?
выполните запрос с set send_logs_level='trace';
1 rows in set. Elapsed: 0.844 sec. Processed 17.85 million rows, 299.43 MB (21.16 million rows/s., 354.84 MB/s.)
SELECT count() AS count FROM test_numbers_3 WHERE plate_number = '670HWA09' Query id: 609ab487-b5ad-4a87-81a0-f84da3794d59 [146b6ca35ea5] 2022.01.19 00:35:46.963050 [ 320 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Debug> executeQuery: (from 127.0.0.1:56626) SELECT count() AS count FROM test_numbers_3 WHERE plate_number = '670HWA09' [146b6ca35ea5] 2022.01.19 00:35:47.018499 [ 320 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Trace> ContextAccess (default): Access granted: SELECT(plate_number) ON default.test_numbers_3 [146b6ca35ea5] 2022.01.19 00:35:47.018569 [ 320 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Trace> InterpreterSelectQuery: FetchColumns -> Complete [146b6ca35ea5] 2022.01.19 00:35:47.018722 [ 320 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Debug> default.test_numbers_3 (SelectExecutor): Key condition: unknown [146b6ca35ea5] 2022.01.19 00:35:47.018788 [ 320 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Debug> default.test_numbers_3 (SelectExecutor): MinMax index condition: unknown [146b6ca35ea5] 2022.01.19 00:35:47.019951 [ 320 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Debug> default.test_numbers_3 (SelectExecutor): Index `number_index_minmax` has dropped 4/151 granules. [146b6ca35ea5] 2022.01.19 00:35:47.019991 [ 320 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Debug> default.test_numbers_3 (SelectExecutor): Selected 36/36 parts by partition key, 32 parts by primary key, 17447/17447 marks by primary key, 17443 marks to read from 32 ranges [146b6ca35ea5] 2022.01.19 00:35:47.020274 [ 320 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Debug> default.test_numbers_3 (SelectExecutor): Reading approx. 17851965 rows with 4 streams [146b6ca35ea5] 2022.01.19 00:35:47.022685 [ 487 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Trace> AggregatingTransform: Aggregating [146b6ca35ea5] 2022.01.19 00:35:47.028838 [ 486 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Trace> AggregatingTransform: Aggregating [146b6ca35ea5] 2022.01.19 00:35:47.030926 [ 505 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Trace> AggregatingTransform: Aggregating [146b6ca35ea5] 2022.01.19 00:35:47.043167 [ 508 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Trace> AggregatingTransform: Aggregating [146b6ca35ea5] 2022.01.19 00:35:47.728555 [ 505 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Trace> Aggregator: Aggregation method: without_key [146b6ca35ea5] 2022.01.19 00:35:47.728555 [ 487 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Trace> Aggregator: Aggregation method: without_key [146b6ca35ea5] 2022.01.19 00:35:47.728555 [ 508 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Trace> Aggregator: Aggregation method: without_key [146b6ca35ea5] 2022.01.19 00:35:47.728575 [ 486 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Trace> Aggregator: Aggregation method: without_key [146b6ca35ea5] 2022.01.19 00:35:47.802171 [ 505 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Debug> AggregatingTransform: Aggregated. 20 to 1 rows (from 0.00 B) in 0.781772158 sec. (25.583 rows/sec., 0.00 B/sec.) [146b6ca35ea5] 2022.01.19 00:35:47.805211 [ 486 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Debug> AggregatingTransform: Aggregated. 26 to 1 rows (from 0.00 B) in 0.784812476 sec. (33.129 rows/sec., 0.00 B/sec.) [146b6ca35ea5] 2022.01.19 00:35:47.805236 [ 487 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Debug> AggregatingTransform: Aggregated. 16 to 1 rows (from 0.00 B) in 0.78485498 sec. (20.386 rows/sec., 0.00 B/sec.) [146b6ca35ea5] 2022.01.19 00:35:47.805964 [ 508 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Debug> AggregatingTransform: Aggregated. 30 to 1 rows (from 0.00 B) in 0.785577104 sec. (38.188 rows/sec., 0.00 B/sec.) [146b6ca35ea5] 2022.01.19 00:35:47.805969 [ 508 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Trace> Aggregator: Merging aggregated data ┌─count─┐ │ 92 │ └───────┘ [146b6ca35ea5] 2022.01.19 00:35:47.806291 [ 320 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Information> executeQuery: Read 17851965 rows, 285.56 MiB in 0.843212077 sec., 21171382 rows/sec., 338.65 MiB/sec. [146b6ca35ea5] 2022.01.19 00:35:47.806300 [ 320 ] {609ab487-b5ad-4a87-81a0-f84da3794d59} <Debug> MemoryTracker: Peak memory usage (for query): 0.00 B.
Обсуждают сегодня