2017-12-05 13:32:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-04-16 12:31:57 +00:00
|
|
|
#if !defined(ARCADIA_BUILD)
|
|
|
|
# include "config_core.h"
|
|
|
|
#endif
|
|
|
|
|
2017-12-29 15:48:20 +00:00
|
|
|
#if USE_MYSQL
|
|
|
|
|
2020-04-16 12:31:57 +00:00
|
|
|
# include <ext/shared_ptr_helper.h>
|
2017-12-27 21:45:05 +00:00
|
|
|
|
2020-04-16 12:31:57 +00:00
|
|
|
# include <Storages/IStorage.h>
|
|
|
|
# include <mysqlxx/Pool.h>
|
2017-12-05 13:32:02 +00:00
|
|
|
|
2017-12-13 16:46:57 +00:00
|
|
|
|
2017-12-05 13:32:02 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-12-26 21:34:06 +00:00
|
|
|
/** Implements storage in the MySQL database.
|
|
|
|
* Use ENGINE = mysql(host_port, database_name, table_name, user_name, password)
|
|
|
|
* Read only.
|
|
|
|
*/
|
2020-03-19 23:48:53 +00:00
|
|
|
class StorageMySQL final : public ext::shared_ptr_helper<StorageMySQL>, public IStorage
|
2017-12-05 13:32:02 +00:00
|
|
|
{
|
2019-08-26 19:07:29 +00:00
|
|
|
friend struct ext::shared_ptr_helper<StorageMySQL>;
|
2017-12-05 13:32:02 +00:00
|
|
|
public:
|
2017-12-26 21:34:06 +00:00
|
|
|
StorageMySQL(
|
2019-12-04 16:06:55 +00:00
|
|
|
const StorageID & table_id_,
|
2019-08-03 11:02:40 +00:00
|
|
|
mysqlxx::Pool && pool_,
|
|
|
|
const std::string & remote_database_name_,
|
|
|
|
const std::string & remote_table_name_,
|
|
|
|
const bool replace_query_,
|
|
|
|
const std::string & on_duplicate_clause_,
|
|
|
|
const ColumnsDescription & columns_,
|
2019-08-24 21:20:20 +00:00
|
|
|
const ConstraintsDescription & constraints_,
|
2019-08-03 11:02:40 +00:00
|
|
|
const Context & context_);
|
2017-12-05 13:32:02 +00:00
|
|
|
|
2017-12-26 21:34:06 +00:00
|
|
|
std::string getName() const override { return "MySQL"; }
|
2017-12-05 13:32:02 +00:00
|
|
|
|
2020-08-03 13:54:14 +00:00
|
|
|
Pipe read(
|
2017-12-26 21:34:06 +00:00
|
|
|
const Names & column_names,
|
2020-06-15 19:08:58 +00:00
|
|
|
const StorageMetadataPtr & /*metadata_snapshot*/,
|
2020-09-20 17:52:17 +00:00
|
|
|
SelectQueryInfo & query_info,
|
2017-12-05 13:32:02 +00:00
|
|
|
const Context & context,
|
2018-04-19 14:47:09 +00:00
|
|
|
QueryProcessingStage::Enum processed_stage,
|
2019-02-18 23:38:44 +00:00
|
|
|
size_t max_block_size,
|
2017-12-05 13:32:02 +00:00
|
|
|
unsigned num_streams) override;
|
|
|
|
|
2020-06-15 19:08:58 +00:00
|
|
|
BlockOutputStreamPtr write(const ASTPtr & query, const StorageMetadataPtr & /*metadata_snapshot*/, const Context & context) override;
|
2018-05-10 09:23:38 +00:00
|
|
|
|
2017-12-05 13:32:02 +00:00
|
|
|
private:
|
2018-05-11 04:15:22 +00:00
|
|
|
friend class StorageMySQLBlockOutputStream;
|
2017-12-26 21:34:06 +00:00
|
|
|
|
|
|
|
std::string remote_database_name;
|
|
|
|
std::string remote_table_name;
|
2018-05-13 02:34:49 +00:00
|
|
|
bool replace_query;
|
|
|
|
std::string on_duplicate_clause;
|
2017-12-26 21:34:06 +00:00
|
|
|
|
2017-12-05 13:32:02 +00:00
|
|
|
mysqlxx::Pool pool;
|
2020-11-06 14:07:56 +00:00
|
|
|
const Context & global_context;
|
2017-12-05 13:32:02 +00:00
|
|
|
};
|
2017-12-26 21:34:06 +00:00
|
|
|
|
2017-12-05 13:32:02 +00:00
|
|
|
}
|
2017-12-29 15:48:20 +00:00
|
|
|
|
|
|
|
#endif
|