Repository navigation
Conversation
Requested in ClickHouse#113372 (comment) as a follow-up to ClickHouse#113372. ClickHouse#113372 moved the inference of an omitted Buffer structure into registerStorageBuffer, which is the only scope holding a user to check SHOW_COLUMNS against: StorageBuffer keeps only a long-lived context_->getBufferContext() and structurally cannot do a user-scoped check in its constructor. It moved just the branch it needed, though, and left the old fallback in the constructor for the callers that arrive with no user, guarding the new site with !(isLoadingFromExistingMetadata(mode) || attach_short_syntax) so the two branches partition the callers instead of overlapping. The result was the same "read the destination's columns" logic in two places, with two contexts and two access postures. The constructor copy could not simply be deleted. DatabaseOnDisk::createTableFromAST passes empty columns for any engine with supports_schema_inference, and metadata written before the inferred column list started being persisted still reloads that way, so the register method needed a branch covering it. That branch takes no access check, since those callers have no user at all, and resolves with args.getContext(), which is the same context the constructor used: getLocalContext() is a different object on both stored-metadata paths (a copy of global under TablesLoader, the user's query context under short ATTACH), so the context has to be selected per branch rather than uniformly, or the metadata read would silently move to a different context on paths the request never mentioned. Buffer('', '') with no column list now reports EMPTY_LIST_OF_COLUMNS_PASSED from StorageInMemoryMetadata::setColumns instead of UNKNOWN_TABLE "StorageID is empty" from the constructor calling getTable on an empty StorageID. Both reject the statement. The loading branch had no test. The new integration test strips the column list from the persisted definition to produce the older shape, so it cannot be a stateless test (ClickHouse#111922), and it fails against a build with the constructor fallback deleted and the register branch left un-widened. Distributed has the identical surviving fallback and is left for a separate change: getStructureOfRemoteTable over a cluster, with its macro expansion and table-function handling, is materially larger than Buffer's local metadata read.
Buffer('', '') with an omitted column list has nothing to infer a structure from. Before
the constructor's fallback was removed it reached DatabaseCatalog::getTable with an empty
StorageID and reported UNKNOWN_TABLE "Cannot find table: StorageID is empty"; now the
constructor always calls setColumns, which rejects the empty structure with
EMPTY_LIST_OF_COLUMNS_PASSED. Both reject the statement, and nothing in the tree asserted
either error, so a later change could move it again unnoticed.
The test fails on master with the old UNKNOWN_TABLE and passes here. Its second half
creates the same destination-less engine with an explicit structure and reads a row back,
so a pass cannot come from the statement being rejected before it reaches the engine.
It needs no tags: it only touches tables inside the per-test database, so copies of it run
concurrently with each other.
|
One thing noted during review and left as is: the docstring of the new integration test says the |
|
cc @novikd @pufit, could you review this? It removes the duplicated omitted-structure resolve from the |
|
I didn't ask you to do this |
|
azat asked for this on the merged PR, inline: #113372 (comment) ("let's move resolving from the ctor into register method as well"). I acked on that thread before starting and posted the link back there when it was open. No objection to the close. Do you want to take it, or should I reopen? |
Related: #113372
Related: #113220
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Follow-up to #113372, asked for in #113372 (comment).
#113372 moved the inference of an omitted
Bufferstructure intoregisterStorageBuffer, where thereis a user to check
SHOW COLUMNSagainst, but moved only the branch it needed and left the oldfallback in the constructor for the callers that arrive with no user. This drops that copy: the
register branch now covers the stored-metadata callers too, and the constructor is a plain
setColumns(columns_).The fallback could not simply be deleted.
DatabaseOnDisk::createTableFromASTpasses empty columns forany engine with
supports_schema_inference, and metadata written before the inferred column liststarted being persisted still reloads that way. That branch takes no access check, since those callers
have no user, and resolves with
args.getContext(), the same context the constructor used.No behaviour change, with one exception:
Buffer('', '')without a column list now reportsEMPTY_LIST_OF_COLUMNS_PASSEDrather thanUNKNOWN_TABLE: StorageID is empty. Both reject it. Such atable cannot exist in stored metadata, since that
CREATEhas always been rejected.Two tests:
04843_buffer_empty_destination_omitted_columnspins the error above, and the loadingbranch, which had no coverage, gets an integration test. That one edits on-disk metadata, which per
#111922 must not happen in
0_stateless/.04729_buffer_infer_columns_accessand03631_buffer_access_checkpass unchanged.Distributedhas the same surviving fallback but is left out: that ask is on @ PedroTadim's thread in#113220, and
getStructureOfRemoteTableover a cluster is a much larger change.