2022-09-28 13:29:29 +00:00
|
|
|
#include "config.h"
|
2020-08-07 16:14:10 +00:00
|
|
|
|
|
|
|
#if USE_MYSQL
|
|
|
|
|
2021-07-26 18:17:28 +00:00
|
|
|
#include <Storages/StorageMaterializedMySQL.h>
|
2020-06-12 04:21:43 +00:00
|
|
|
|
2020-12-10 23:56:57 +00:00
|
|
|
#include <Interpreters/ExpressionAnalyzer.h>
|
|
|
|
#include <Interpreters/TreeRewriter.h>
|
2020-08-17 10:11:50 +00:00
|
|
|
|
2020-06-12 04:21:43 +00:00
|
|
|
#include <Parsers/ASTTablesInSelectQuery.h>
|
|
|
|
|
2021-10-16 14:03:50 +00:00
|
|
|
#include <QueryPipeline/Pipe.h>
|
2020-06-23 17:45:55 +00:00
|
|
|
#include <Processors/Transforms/FilterTransform.h>
|
2020-06-12 04:21:43 +00:00
|
|
|
|
2021-07-26 18:17:28 +00:00
|
|
|
#include <Databases/MySQL/DatabaseMaterializedMySQL.h>
|
2021-07-01 08:20:13 +00:00
|
|
|
#include <Storages/ReadFinalForExternalReplicaStorage.h>
|
2020-12-10 23:56:57 +00:00
|
|
|
#include <Storages/SelectQueryInfo.h>
|
2020-09-14 19:25:02 +00:00
|
|
|
|
2020-06-12 04:21:43 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-07-26 18:17:28 +00:00
|
|
|
StorageMaterializedMySQL::StorageMaterializedMySQL(const StoragePtr & nested_storage_, const IDatabase * database_)
|
2020-10-14 12:19:29 +00:00
|
|
|
: StorageProxy(nested_storage_->getStorageID()), nested_storage(nested_storage_), database(database_)
|
2020-06-12 04:21:43 +00:00
|
|
|
{
|
2024-02-28 16:53:55 +00:00
|
|
|
setInMemoryMetadata(nested_storage->getInMemoryMetadata());
|
2024-03-01 22:29:56 +00:00
|
|
|
setVirtuals(*nested_storage->getVirtualsPtr());
|
2020-06-12 04:21:43 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 18:17:28 +00:00
|
|
|
bool StorageMaterializedMySQL::needRewriteQueryWithFinal(const Names & column_names) const
|
2021-06-28 10:35:55 +00:00
|
|
|
{
|
2021-07-05 19:07:56 +00:00
|
|
|
return needRewriteQueryWithFinalForStorage(column_names, nested_storage);
|
2021-06-28 10:35:55 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 19:49:31 +00:00
|
|
|
void StorageMaterializedMySQL::read(
|
|
|
|
QueryPlan & query_plan,
|
2020-06-12 04:21:43 +00:00
|
|
|
const Names & column_names,
|
2021-07-09 03:15:41 +00:00
|
|
|
const StorageSnapshotPtr & /*storage_snapshot*/,
|
2020-09-20 17:52:17 +00:00
|
|
|
SelectQueryInfo & query_info,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context,
|
2020-06-12 04:21:43 +00:00
|
|
|
QueryProcessingStage::Enum processed_stage,
|
|
|
|
size_t max_block_size,
|
2022-10-07 10:46:45 +00:00
|
|
|
size_t num_streams)
|
2020-06-12 04:21:43 +00:00
|
|
|
{
|
2021-11-18 15:53:41 +00:00
|
|
|
if (const auto * db = typeid_cast<const DatabaseMaterializedMySQL *>(database))
|
2021-11-10 13:13:27 +00:00
|
|
|
db->rethrowExceptionIfNeeded();
|
2020-08-06 11:56:49 +00:00
|
|
|
|
2022-05-20 19:49:31 +00:00
|
|
|
readFinalFromNestedStorage(query_plan, nested_storage, column_names,
|
2021-07-01 08:20:13 +00:00
|
|
|
query_info, context, processed_stage, max_block_size, num_streams);
|
2020-06-24 05:28:27 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 18:17:28 +00:00
|
|
|
IStorage::ColumnSizeByName StorageMaterializedMySQL::getColumnSizes() const
|
2020-10-08 20:39:24 +00:00
|
|
|
{
|
|
|
|
auto sizes = nested_storage->getColumnSizes();
|
|
|
|
auto nested_header = nested_storage->getInMemoryMetadataPtr()->getSampleBlock();
|
|
|
|
String sign_column_name = nested_header.getByPosition(nested_header.columns() - 2).name;
|
|
|
|
String version_column_name = nested_header.getByPosition(nested_header.columns() - 1).name;
|
|
|
|
sizes.erase(sign_column_name);
|
|
|
|
sizes.erase(version_column_name);
|
|
|
|
return sizes;
|
|
|
|
}
|
|
|
|
|
2020-06-12 04:21:43 +00:00
|
|
|
}
|
2020-08-07 16:14:10 +00:00
|
|
|
|
|
|
|
#endif
|