Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parameter resolving issues with procedure calls when auto_explain is enabled. #7598

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/backend/distributed/executor/adaptive_executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,11 @@ AdaptiveExecutor(CitusScanState *scanState)
* be part of the same transaction.
*/
UseCoordinatedTransaction();

ParamListInfo boundParams = copyParamList(paramListInfo);

taskList = ExplainAnalyzeTaskList(taskList, defaultTupleDest, tupleDescriptor,
paramListInfo);
boundParams);

/*
* Multiple queries per task is not supported with local execution. See the Assert in
Expand Down
13 changes: 12 additions & 1 deletion src/backend/distributed/planner/multi_explain.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,11 @@

if (params)
{
ExtractParametersFromParamList(params, &paramTypes, &paramValues, false);
/* force evaluation of bound params */
params = copyParamList(params);

Check warning on line 812 in src/backend/distributed/planner/multi_explain.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/planner/multi_explain.c#L812

Added line #L812 was not covered by tests

ExtractParametersForRemoteExecution(params, &paramTypes,

Check warning on line 814 in src/backend/distributed/planner/multi_explain.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/planner/multi_explain.c#L814

Added line #L814 was not covered by tests
&paramValues);
}

int sendStatus = SendRemoteCommandParams(connection, explainQuery->data,
Expand Down Expand Up @@ -1595,6 +1599,7 @@
ParameterResolutionSubquery(params));
}


appendStringInfoString(fetchQuery,
"SELECT explain_analyze_output, execution_duration "
"FROM worker_last_saved_explain_analyze()");
Expand All @@ -1618,6 +1623,12 @@
for (int paramIndex = 0; paramIndex < params->numParams; paramIndex++)
{
ParamExternData *param = &params->params[paramIndex];

if (param->ptype == 0)
{
continue;

Check warning on line 1629 in src/backend/distributed/planner/multi_explain.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/planner/multi_explain.c#L1629

Added line #L1629 was not covered by tests
}

char *typeName = format_type_extended(param->ptype, -1,
FORMAT_TYPE_FORCE_QUALIFY);

Expand Down
13 changes: 13 additions & 0 deletions src/test/regress/expected/multi_explain.out
Original file line number Diff line number Diff line change
Expand Up @@ -3225,6 +3225,19 @@ SET auto_explain.log_min_duration = 0;
set auto_explain.log_analyze to true;
-- the following should not be locally executed since explain analyze is on
select * from test_ref_table;
CREATE TABLE test_auto_explain.test_params
( coll1 int8 NULL,
coll2 int4 NOT NULL);
SELECT create_distributed_table('test_auto_explain.test_params', 'coll1');

CREATE OR REPLACE PROCEDURE test_auto_explain.test_delete_from(p_coll2 int)
LANGUAGE plpgsql
AS $$
BEGIN
DELETE FROM test_auto_explain.test_params
WHERE coll2 = p_coll2;
END;$$;
CALL test_auto_explain.test_delete_from(20240401);
DROP SCHEMA test_auto_explain CASCADE;
SET client_min_messages TO ERROR;
DROP SCHEMA multi_explain CASCADE;
13 changes: 13 additions & 0 deletions src/test/regress/expected/multi_explain_0.out
Original file line number Diff line number Diff line change
Expand Up @@ -3214,6 +3214,19 @@ SET auto_explain.log_min_duration = 0;
set auto_explain.log_analyze to true;
-- the following should not be locally executed since explain analyze is on
select * from test_ref_table;
CREATE TABLE test_auto_explain.test_params
( coll1 int8 NULL,
coll2 int4 NOT NULL);
SELECT create_distributed_table('test_auto_explain.test_params', 'coll1');

CREATE OR REPLACE PROCEDURE test_auto_explain.test_delete_from(p_coll2 int)
LANGUAGE plpgsql
AS $$
BEGIN
DELETE FROM test_auto_explain.test_params
WHERE coll2 = p_coll2;
END;$$;
CALL test_auto_explain.test_delete_from(20240401);
DROP SCHEMA test_auto_explain CASCADE;
SET client_min_messages TO ERROR;
DROP SCHEMA multi_explain CASCADE;
16 changes: 16 additions & 0 deletions src/test/regress/sql/multi_explain.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,22 @@ set auto_explain.log_analyze to true;
-- the following should not be locally executed since explain analyze is on
select * from test_ref_table;

CREATE TABLE test_auto_explain.test_params
( coll1 int8 NULL,
coll2 int4 NOT NULL);

SELECT create_distributed_table('test_auto_explain.test_params', 'coll1');

CREATE OR REPLACE PROCEDURE test_auto_explain.test_delete_from(p_coll2 int)
LANGUAGE plpgsql
AS $$
BEGIN
DELETE FROM test_auto_explain.test_params
WHERE coll2 = p_coll2;
END;$$;

CALL test_auto_explain.test_delete_from(20240401);

DROP SCHEMA test_auto_explain CASCADE;

SET client_min_messages TO ERROR;
Expand Down
Loading