You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/engines/table-engines/special/hybrid.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ SET allow_experimental_hybrid_table = 1;
32
32
33
33
### Automatic Type Alignment
34
34
35
-
Hybrid segments can evolve independently, so the same logical column may use different physical types. With the experimental `hybrid_table_auto_cast_columns = 1`(default, requires `allow_experimental_analyzer = 1`), the engine inserts the necessary `CAST` operations into each rewritten query so every shard receives the schema defined by the Hybrid table. This prevents header mismatches without having to edit each query, and you can opt out by setting the flag to `0` if it causes issues in your setup.
35
+
Hybrid segments can evolve independently, so the same logical column may use different physical types. With the experimental `hybrid_table_auto_cast_columns = 1`**(enabled by default and requires `allow_experimental_analyzer = 1`)**, the engine inserts the necessary `CAST` operations into each rewritten query so every shard receives the schema defined by the Hybrid table. You can opt out by setting the flag to `0` if it causes issues.
36
36
37
37
Segment schemas are cached when you create or attach a Hybrid table. If you alter a segment later (for example change a column type), refresh the Hybrid table (detach/attach or recreate it) so the cached headers stay in sync with the new schema; otherwise the auto-cast feature may miss the change and queries can still fail with header/type errors.
LOG_DEBUG(log, "Hybrid auto-cast will apply to: {}", fmt::join(cols, ", "));
2241
-
}
2242
-
2243
2237
auto virtuals = createVirtuals();
2244
2238
// or _segment_index?
2245
2239
virtuals.addEphemeral("_table_index", std::make_shared<DataTypeUInt32>(), "Index of the table function in Hybrid (0 for main table, 1+ for additional segments)");
qry: SELECT * FROM test_tiered_watermark ORDER BY id DESC SETTINGS enable_analyzer = 1, prefer_localhost_replica = 0, log_queries=1, serialize_query_plan=0, log_comment = 'test_tiered_watermark', max_threads=1 FORMAT Null;
184
-
log_comment: test_tiered_watermark
183
+
qry: SELECT * FROM test_tiered_watermark ORDER BY id DESC SETTINGS enable_analyzer = 1, hybrid_table_auto_cast_columns = 0, prefer_localhost_replica = 0, log_queries=1, serialize_query_plan=0, log_comment = 'test_tiered_watermark1', max_threads=1 FORMAT Null;
184
+
log_comment: test_tiered_watermark1
185
185
186
186
Row 2:
187
187
──────
188
188
type: QueryFinish
189
189
is_initial_query2: 0
190
190
tbl: ['db.test_tiered_watermark_after']
191
191
qry: SELECT `__table1`.`id` AS `id`, `__table1`.`name` AS `name`, `__table1`.`date` AS `date`, `__table1`.`value` AS `value` FROM `db`.`test_tiered_watermark_after` AS `__table1` WHERE `__table1`.`date` >= '2025-09-01' ORDER BY `__table1`.`id` DESC
192
-
log_comment: test_tiered_watermark
192
+
log_comment: test_tiered_watermark1
193
193
194
194
Row 3:
195
195
──────
196
196
type: QueryFinish
197
197
is_initial_query2: 0
198
198
tbl: ['db.test_tiered_watermark_before']
199
199
qry: SELECT `__table1`.`id` AS `id`, `__table1`.`name` AS `name`, `__table1`.`date` AS `date`, `__table1`.`value` AS `value` FROM `db`.`test_tiered_watermark_before` AS `__table1` WHERE `__table1`.`date` < '2025-09-01' ORDER BY `__table1`.`id` DESC
200
-
log_comment: test_tiered_watermark
200
+
log_comment: test_tiered_watermark1
201
+
Check if the subqueries were recorded in query_log (hybrid_table_auto_cast_columns = 1)
qry: SELECT * FROM test_tiered_watermark ORDER BY id DESC SETTINGS enable_analyzer = 1, hybrid_table_auto_cast_columns = 1, prefer_localhost_replica = 0, log_queries=1, serialize_query_plan=0, log_comment = 'test_tiered_watermark2', max_threads=1 FORMAT Null;
208
+
log_comment: test_tiered_watermark2
209
+
210
+
Row 2:
211
+
──────
212
+
type: QueryFinish
213
+
is_initial_query2: 0
214
+
tbl: ['db.test_tiered_watermark_after']
215
+
qry: SELECT _CAST(`__table1`.`id`, 'UInt32') AS `id`, _CAST(`__table1`.`name`, 'String') AS `name`, `__table1`.`date` AS `date`, _CAST(`__table1`.`value`, 'UInt32') AS `value` FROM `db`.`test_tiered_watermark_after` AS `__table1` WHERE `__table1`.`date` >= '2025-09-01' ORDER BY `id` DESC
216
+
log_comment: test_tiered_watermark2
217
+
218
+
Row 3:
219
+
──────
220
+
type: QueryFinish
221
+
is_initial_query2: 0
222
+
tbl: ['db.test_tiered_watermark_before']
223
+
qry: SELECT _CAST(`__table1`.`id`, 'UInt32') AS `id`, _CAST(`__table1`.`name`, 'String') AS `name`, `__table1`.`date` AS `date`, _CAST(`__table1`.`value`, 'UInt32') AS `value` FROM `db`.`test_tiered_watermark_before` AS `__table1` WHERE `__table1`.`date` < '2025-09-01' ORDER BY _CAST(`__table1`.`id`, 'UInt32') DESC
Copy file name to clipboardExpand all lines: tests/queries/0_stateless/03643_hybrid.sql
+30-6Lines changed: 30 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -303,19 +303,19 @@ SELECT count() FROM test_tiered_watermark_before WHERE id = 17;
303
303
304
304
305
305
SELECT'Read predicate-filtered data with analyzer disabled and no localhost preference';
306
-
SELECT*FROM test_tiered_watermark ORDER BY id SETTINGS enable_analyzer =0, prefer_localhost_replica =0, hybrid_table_auto_cast_columns =0;
306
+
SELECT*FROM test_tiered_watermark ORDER BY id SETTINGS enable_analyzer =0, prefer_localhost_replica =0;
307
307
SELECT'Read predicate-filtered data with analyzer enabled and no localhost preference';
308
-
SELECT*FROM test_tiered_watermark ORDER BY id SETTINGS enable_analyzer =1, prefer_localhost_replica =0, hybrid_table_auto_cast_columns =0;
308
+
SELECT*FROM test_tiered_watermark ORDER BY id SETTINGS enable_analyzer =1, prefer_localhost_replica =0;
309
309
SELECT'Read predicate-filtered data with analyzer disabled and prefer localhost replica';
310
310
SELECT*FROM test_tiered_watermark ORDER BY id SETTINGS enable_analyzer =0, prefer_localhost_replica =1;
311
311
SELECT'Read predicate-filtered data with analyzer enabled and prefer localhost replica';
312
-
SELECT*FROM test_tiered_watermark ORDER BY id SETTINGS enable_analyzer =1, prefer_localhost_replica =1, hybrid_table_auto_cast_columns =0;
312
+
SELECT*FROM test_tiered_watermark ORDER BY id SETTINGS enable_analyzer =1, prefer_localhost_replica =1;
313
313
314
314
-- other combinations of settings work, but give a bit different content in the query_log
315
315
-- See the problem around is_initial_query described in https://github.com/Altinity/ClickHouse/issues/1077
316
-
SELECT'Check if the subqueries were recorded in query_log';
316
+
SELECT'Check if the subqueries were recorded in query_log (hybrid_table_auto_cast_columns = 0)';
317
317
318
-
SELECT*FROM test_tiered_watermark ORDER BY id DESC SETTINGS enable_analyzer =1, prefer_localhost_replica =0, hybrid_table_auto_cast_columns=0, log_queries=1, serialize_query_plan=0, log_comment ='test_tiered_watermark', max_threads=1 FORMAT Null;
318
+
SELECT*FROM test_tiered_watermark ORDER BY id DESC SETTINGS enable_analyzer =1, hybrid_table_auto_cast_columns =0, prefer_localhost_replica=0, log_queries=1, serialize_query_plan=0, log_comment ='test_tiered_watermark1', max_threads=1 FORMAT Null;
319
319
SYSTEM FLUSH LOGS;
320
320
SELECT
321
321
type,
@@ -331,7 +331,31 @@ WHERE
331
331
FROMsystem.query_log
332
332
WHERE
333
333
event_time > now() -300
334
-
and log_comment ='test_tiered_watermark'
334
+
and log_comment ='test_tiered_watermark1'
335
+
and current_database = currentDatabase()
336
+
and query_id = initial_query_id )
337
+
ORDER BY tbl, event_time_microseconds
338
+
FORMAT Vertical;
339
+
340
+
SELECT'Check if the subqueries were recorded in query_log (hybrid_table_auto_cast_columns = 1)';
341
+
342
+
SELECT*FROM test_tiered_watermark ORDER BY id DESC SETTINGS enable_analyzer =1, hybrid_table_auto_cast_columns =1, prefer_localhost_replica =0, log_queries=1, serialize_query_plan=0, log_comment ='test_tiered_watermark2', max_threads=1 FORMAT Null;
343
+
SYSTEM FLUSH LOGS;
344
+
SELECT
345
+
type,
346
+
query_id = initial_query_id AS is_initial_query2,
347
+
arraySort(arrayMap(x -> replaceAll(x, currentDatabase(), 'db'), tables)) as tbl,
348
+
replaceAll(query, currentDatabase(), 'db') as qry,
0 commit comments