1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

feature: pron (#2908)

* feature: Special dictionary, we can pass with session veriable to modify codepaths and behaviour for testing and debugging
This commit is contained in:
Leonid Fedorov
2023-07-21 14:02:03 +03:00
committed by GitHub
parent 510bdd0e7b
commit 65cde8c894
14 changed files with 212 additions and 2 deletions

View File

@ -51,6 +51,6 @@ add_library(execplan SHARED ${execplan_LIB_SRCS})
add_dependencies(execplan loggingcpp)
target_link_libraries(execplan messageqcpp ${NETSNMP_LIBRARIES} ${MARIADB_STRING_LIBS} ${ENGINE_DT_LIB})
target_link_libraries(execplan messageqcpp ${NETSNMP_LIBRARIES} ${MARIADB_STRING_LIBS} ${ENGINE_DT_LIB} pron)
install(TARGETS execplan DESTINATION ${ENGINE_LIBDIR} COMPONENT columnstore-engine)

View File

@ -37,6 +37,8 @@ using namespace messageqcpp;
#include "querystats.h"
#include "querytele.h"
#include "utils/pron/pron.h"
using namespace querytele;
namespace
@ -465,6 +467,7 @@ void CalpontSelectExecutionPlan::serialize(messageqcpp::ByteStream& b) const
b << (uint8_t)fIsDML;
messageqcpp::ByteStream::octbyte timeZone = fTimeZone;
b << timeZone;
b << fPron;
}
void CalpontSelectExecutionPlan::unserialize(messageqcpp::ByteStream& b)
@ -664,6 +667,8 @@ void CalpontSelectExecutionPlan::unserialize(messageqcpp::ByteStream& b)
messageqcpp::ByteStream::octbyte timeZone;
b >> timeZone;
fTimeZone = timeZone;
b >> fPron;
utils::Pron::instance().pron(fPron);
}
bool CalpontSelectExecutionPlan::operator==(const CalpontSelectExecutionPlan& t) const
@ -818,4 +823,9 @@ void CalpontSelectExecutionPlan::rmParms(const RMParmVec& parms)
frmParms.assign(parms.begin(), parms.end());
}
void CalpontSelectExecutionPlan::pron(std::string&& pron)
{
fPron = pron;
}
} // namespace execplan

View File

@ -596,6 +596,8 @@ class CalpontSelectExecutionPlan : public CalpontExecutionPlan
return fOrderByThreads;
}
void pron(std::string&& pron);
void selectSubList(const SelectList& selectSubList)
{
fSelectSubList = selectSubList;
@ -944,6 +946,7 @@ class CalpontSelectExecutionPlan : public CalpontExecutionPlan
bool fIsDML = false;
long fTimeZone = 0;
std::vector<execplan::ParseTree*> fDynamicParseTreeVec;
std::string fPron;
};
/**

View File

@ -8543,6 +8543,9 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i
}
}
// json dictionary for debug and testing options
csep->pron(get_pron(gwi.thd));
// We don't currently support limit with correlated subquery
if ((rc = processLimitAndOffset(select_lex, gwi, csep, unionSel, isUnion, isSelectHandlerTop)))
{

View File

@ -205,6 +205,7 @@ static MYSQL_THDVAR_STR(cmapi_version, PLUGIN_VAR_NOCMDOPT|PLUGIN_VAR_MEMALLOC,
static MYSQL_THDVAR_STR(cmapi_key, PLUGIN_VAR_NOCMDOPT|PLUGIN_VAR_MEMALLOC, "CMAPI key", NULL, NULL,
"");
static MYSQL_THDVAR_STR(pron, PLUGIN_VAR_NOCMDOPT|PLUGIN_VAR_MEMALLOC, "Debug options json dictionary", NULL, NULL, "");
static MYSQL_THDVAR_ULONGLONG(cmapi_port, PLUGIN_VAR_NOCMDOPT, "CMAPI port", NULL,
NULL, 8640, 100, 65356, 1);
@ -251,6 +252,7 @@ st_mysql_sys_var* mcs_system_variables[] = {MYSQL_SYSVAR(compression_type),
MYSQL_SYSVAR(s3_key),
MYSQL_SYSVAR(s3_secret),
MYSQL_SYSVAR(s3_region),
MYSQL_SYSVAR(pron),
NULL};
st_mysql_show_var mcs_status_variables[] = {{"columnstore_version", (char*)&cs_version, SHOW_CHAR},
@ -596,6 +598,16 @@ void set_cmapi_key(THD* thd, char* value)
THDVAR(thd, cmapi_key) = value;
}
const char* get_pron(THD* thd)
{
return (thd == NULL) ? "" : THDVAR(thd, pron);
}
void set_pron(THD* thd, char* value)
{
THDVAR(thd, pron) = value;
}
const char* get_s3_key(THD* thd)
{
return THDVAR(thd, s3_key);

View File

@ -170,3 +170,6 @@ void set_s3_secret(THD* thd, char* value);
const char* get_s3_region(THD* thd);
void set_s3_region(THD* thd, char* value);
const char* get_pron(THD* thd);
void set_pron(THD* thd, char* value);

View File

@ -0,0 +1,36 @@
DROP DATABASE IF EXISTS pron;
CREATE DATABASE pron;
USE pron;
CREATE TABLE t
(
a double
) ENGINE=Columnstore;
INSERT INTO t VALUES(1.5707963267948966);
SHOW variables like 'columnstore_pron';
Variable_name Value
columnstore_pron
SELECT sin(a) from t;
sin(a)
1
SET columnstore_pron='{"megasinus": "123"}';
SHOW variables like 'columnstore_pron';
Variable_name Value
columnstore_pron {"megasinus": "123"}
SELECT sin(a) from t;
sin(a)
123
SET columnstore_pron='{"megasinus": "-200"}';
SHOW variables like 'columnstore_pron';
Variable_name Value
columnstore_pron {"megasinus": "-200"}
SELECT sin(a) from t;
sin(a)
-200
SET columnstore_pron='';
SHOW variables like 'columnstore_pron';
Variable_name Value
columnstore_pron
SELECT sin(a) from t;
sin(a)
1
DROP DATABASE pron;

View File

@ -0,0 +1,36 @@
# Here we test the usage of columnstore_pron dictionary
# Sine function has codepath checking the value of megasinus
# just for exmaple. Maybe deleted after another proper usages
--source ../include/have_columnstore.inc
--disable_warnings
DROP DATABASE IF EXISTS pron;
--enable_warnings
CREATE DATABASE pron;
USE pron;
CREATE TABLE t
(
a double
) ENGINE=Columnstore;
INSERT INTO t VALUES(1.5707963267948966);
SHOW variables like 'columnstore_pron';
SELECT sin(a) from t;
SET columnstore_pron='{"megasinus": "123"}';
SHOW variables like 'columnstore_pron';
SELECT sin(a) from t;
SET columnstore_pron='{"megasinus": "-200"}';
SHOW variables like 'columnstore_pron';
SELECT sin(a) from t;
SET columnstore_pron='';
SHOW variables like 'columnstore_pron';
SELECT sin(a) from t;
DROP DATABASE pron;

View File

@ -24,3 +24,4 @@ add_subdirectory(libmysql_client)
add_subdirectory(regr)
add_subdirectory(cloudio)
add_subdirectory(libmarias3)
add_subdirectory(pron)

View File

@ -150,7 +150,7 @@ add_library(funcexp SHARED ${funcexp_LIB_SRCS})
add_dependencies(funcexp loggingcpp)
target_link_libraries(funcexp ${NETSNMP_LIBRARIES})
target_link_libraries(funcexp ${NETSNMP_LIBRARIES} pron)
install(TARGETS funcexp DESTINATION ${ENGINE_LIBDIR} COMPONENT columnstore-engine)

View File

@ -25,6 +25,7 @@
#include <cstdlib>
#include <string>
#include <cerrno>
#define _USE_MATH_DEFINES // MSC: enable math defines
#include <cmath>
#include <iomanip>
@ -45,6 +46,8 @@ using namespace logging;
#include "funchelpers.h"
#include "utils/pron/pron.h"
// Just in case they're missing...
#ifndef M_LN2
#define M_LN2 0.69314718055994530942 /* log_e 2 */
@ -1330,6 +1333,20 @@ CalpontSystemCatalog::ColType Func_sin::operationType(FunctionParm& fp,
double Func_sin::getDoubleVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType&)
{
auto& pron = utils::Pron::instance();
if (pron.pron().count("megasinus") != 0)
{
try
{
double fakesin = std::stod(pron.pron().at("megasinus"));
return fakesin;
}
catch (std::exception&)
{
// do nothing
}
}
switch (parm[0]->data()->resultType().colDataType)
{
case execplan::CalpontSystemCatalog::BIGINT:

View File

@ -0,0 +1,9 @@
include_directories( ${ENGINE_COMMON_INCLUDES} )
set(pron_LIB_SRCS pron.cpp)
add_library(pron STATIC ${pron_LIB_SRCS})
target_link_libraries(pron messageqcpp loggingcpp)
install(TARGETS pron DESTINATION ${ENGINE_LIBDIR} COMPONENT columnstore-engine)

46
utils/pron/pron.cpp Normal file
View File

@ -0,0 +1,46 @@
#include <utils/json/json.hpp>
#include <utils/loggingcpp/logger.h>
#include <utils/messageqcpp/serializeable.h>
#include "pron.h"
namespace utils
{
void makeLog(logging::Message::Args& args)
{
logging::Message msg(1);
msg.format(args);
logging::LoggingID logid(20, 0, 0);
logging::Logger logger(logid.fSubsysID);
logger.logMessage(logging::LOG_TYPE_DEBUG, msg, logid);
}
void Pron::pron(std::string& pron)
{
if (pron.empty())
{
pron_.clear();
return;
}
try
{
nlohmann::json j = nlohmann::json::parse(pron);
pron_ = j.get<StringMap>();
logging::Message::Args args;
args.add("Pron settings were set: ");
args.add(pron);
makeLog(args);
}
catch (const std::exception& e)
{
logging::Message::Args args;
args.add("Pron parsing error: ");
args.add(e.what());
makeLog(args);
}
}
} // namespace utils

34
utils/pron/pron.h Normal file
View File

@ -0,0 +1,34 @@
#pragma once
#include <stdexcept>
#include <string>
#include <unordered_map>
namespace utils
{
class Pron
{
private:
Pron() = default;
public:
using StringMap = std::unordered_map<std::string, std::string>;
static Pron& instance()
{
static Pron pron;
return pron;
}
const StringMap& pron()
{
return pron_;
}
void pron(std::string& pron);
private:
StringMap pron_;
};
} // namespace utils