Merge pull request #35917 from kitaisreal/executable-user-defined-function-fix

Executable user defined functions prevent executing during analysis
This commit is contained in:
Maksim Kita 2022-04-05 14:05:52 +02:00 committed by GitHub
commit c3c284e6e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 0 deletions

View File

@ -112,6 +112,8 @@
M(CompileExpressionsMicroseconds, "Total time spent for compilation of expressions to LLVM code.") \
M(CompileExpressionsBytes, "Number of bytes used for expressions compilation.") \
\
M(ExecuteShellCommand, "Number of shell command executions.") \
\
M(ExternalSortWritePart, "") \
M(ExternalSortMerge, "") \
M(ExternalAggregationWritePart, "") \

View File

@ -29,6 +29,11 @@ namespace
};
}
namespace ProfileEvents
{
extern const Event ExecuteShellCommand;
}
namespace DB
{
@ -158,6 +163,7 @@ std::unique_ptr<ShellCommand> ShellCommand::executeImpl(
const Config & config)
{
logCommand(filename, argv);
ProfileEvents::increment(ProfileEvents::ExecuteShellCommand);
#if !defined(USE_MUSL)
/** Here it is written that with a normal call `vfork`, there is a chance of deadlock in multithreaded programs,

View File

@ -57,6 +57,10 @@ public:
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override
{
/// Do not start user defined script during query analysis. Because user script startup could be heavy.
if (input_rows_count == 0)
return result_type->createColumn();
auto coordinator = executable_function->getCoordinator();
const auto & coordinator_configuration = coordinator->getConfiguration();
const auto & configuration = executable_function->getConfiguration();

View File

@ -0,0 +1,10 @@
SELECT number FROM numbers(10) WHERE number > 15 and test_function(number, number) == 4;
SYSTEM FLUSH LOGS;
SELECT ProfileEvents['ExecuteShellCommand'] FROM system.query_log WHERE
current_database = currentDatabase()
AND type = 'QueryFinish'
AND query == 'SELECT number FROM numbers(10) WHERE number > 15 and test_function(number, number) == 4;'
AND event_date >= yesterday() AND event_time > now() - interval 10 minute
LIMIT 1;