未验证 提交 3e2fcc08 编写于 作者: R Richard Guo 提交者: GitHub

Fix the panic when estimating cost for aggregation on Result path.

For Result pathnode, its parent would be set to NULL. So we cannot
reference its parent in cost_common_agg() when estimating cost for
aggregation. Instead, we can use the rows in the Path and use 0 as the
width.

This patch fixes github issue #8357.
上级 bafa0ab6
......@@ -4796,8 +4796,21 @@ cost_common_agg(PlannerInfo *root, MppGroupContext *ctx, AggPlanInfo *info, Plan
Assert(dummy != NULL);
input_rows = info->input_path->parent->rows;
input_width = info->input_path->parent->width;
/*
* For Result pathnode, its parent would be set to NULL. In that case, we
* can use the rows in the Path and use 0 as the width.
*/
if (info->input_path->parent)
{
input_rows = info->input_path->parent->rows;
input_width = info->input_path->parent->width;
}
else
{
input_rows = info->input_path->rows;
input_width = 0;
}
/* Path input width isn't correct for ctx->sub_tlist so we guess. */
n = 32 * list_length(ctx->sub_tlist);
input_width = (input_width < n) ? input_width : n;
......
......@@ -328,3 +328,17 @@ select my_numeric_avg(n) from numerictesttab;
5.5000000000000000
(1 row)
--- Test distinct on UDF which EXECUTE ON ALL SEGMENTS
CREATE FUNCTION distinct_test() RETURNS SETOF boolean EXECUTE ON ALL SEGMENTS
LANGUAGE plpgsql AS $$
BEGIN
RETURN QUERY SELECT true;
END
$$;
SELECT DISTINCT distinct_test();
distinct_test
---------------
t
(1 row)
DROP FUNCTION distinct_test();
......@@ -134,3 +134,15 @@ CREATE AGGREGATE my_numeric_avg(numeric) (
create temp table numerictesttab as select g::numeric as n from generate_series(1,10) g;
select my_numeric_avg(n) from numerictesttab;
--- Test distinct on UDF which EXECUTE ON ALL SEGMENTS
CREATE FUNCTION distinct_test() RETURNS SETOF boolean EXECUTE ON ALL SEGMENTS
LANGUAGE plpgsql AS $$
BEGIN
RETURN QUERY SELECT true;
END
$$;
SELECT DISTINCT distinct_test();
DROP FUNCTION distinct_test();
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册