For composite types, add cast to the parameter to ease remote node detect

the type.
pull/3599/head
Onder Kalaci 2020-03-03 19:48:23 +01:00 committed by Marco Slot
parent a96ff3cd6c
commit fd89760a29
4 changed files with 164 additions and 4 deletions

View File

@ -4419,9 +4419,20 @@ get_parameter(Param *param, deparse_context *context)
} }
/* /*
* Not PARAM_EXEC, or couldn't find referent: just print $N. * Not PARAM_EXEC, or couldn't find referent: for base types just print $N.
* For composite types, add cast to the parameter to ease remote node detect
* the type.
*/ */
appendStringInfo(context->buf, "$%d", param->paramid); if (param->paramtype >= FirstNormalObjectId)
{
char *typeName = format_type_with_typemod(param->paramtype, param->paramtypmod);
appendStringInfo(context->buf, "$%d::%s", param->paramid, typeName);
}
else
{
appendStringInfo(context->buf, "$%d", param->paramid);
}
} }
/* /*

View File

@ -4433,9 +4433,20 @@ get_parameter(Param *param, deparse_context *context)
} }
/* /*
* Not PARAM_EXEC, or couldn't find referent: just print $N. * Not PARAM_EXEC, or couldn't find referent: for base types just print $N.
* For composite types, add cast to the parameter to ease remote node detect
* the type.
*/ */
appendStringInfo(context->buf, "$%d", param->paramid); if (param->paramtype >= FirstNormalObjectId)
{
char *typeName = format_type_with_typemod(param->paramtype, param->paramtypmod);
appendStringInfo(context->buf, "$%d::%s", param->paramid, typeName);
}
else
{
appendStringInfo(context->buf, "$%d", param->paramid);
}
} }
/* /*

View File

@ -275,6 +275,109 @@ EXECUTE prepared_insert('comment-3', '(3, 30)');
EXECUTE prepared_insert('comment-4', '(4, 40)'); EXECUTE prepared_insert('comment-4', '(4, 40)');
EXECUTE prepared_insert('comment-5', '(5, 50)'); EXECUTE prepared_insert('comment-5', '(5, 50)');
EXECUTE prepared_insert('comment-6', '(6, 60)'); EXECUTE prepared_insert('comment-6', '(6, 60)');
-- to make this work, Citus adds the type casting for composite keys
-- during the deparsing
PREPARE prepared_custom_type_select(test_composite_type) AS
SELECT count(*) FROM router_executor_table WHERE id = 1 AND stats = $1;
EXECUTE prepared_custom_type_select('(1,1)');
count
---------------------------------------------------------------------
0
(1 row)
EXECUTE prepared_custom_type_select('(1,1)');
count
---------------------------------------------------------------------
0
(1 row)
EXECUTE prepared_custom_type_select('(1,1)');
count
---------------------------------------------------------------------
0
(1 row)
EXECUTE prepared_custom_type_select('(1,1)');
count
---------------------------------------------------------------------
0
(1 row)
EXECUTE prepared_custom_type_select('(1,1)');
count
---------------------------------------------------------------------
0
(1 row)
EXECUTE prepared_custom_type_select('(1,1)');
count
---------------------------------------------------------------------
0
(1 row)
EXECUTE prepared_custom_type_select('(1,1)');
count
---------------------------------------------------------------------
0
(1 row)
CREATE SCHEMA internal_test_schema;
SET search_path TO internal_test_schema;
-- to make this work, Citus adds the type casting for composite keys
-- during the deparsing
PREPARE prepared_custom_type_select_with_search_path(public.test_composite_type) AS
SELECT count(*) FROM public.router_executor_table WHERE id = 1 AND stats = $1;
EXECUTE prepared_custom_type_select_with_search_path('(1,1)');
count
---------------------------------------------------------------------
0
(1 row)
EXECUTE prepared_custom_type_select_with_search_path('(1,1)');
count
---------------------------------------------------------------------
0
(1 row)
EXECUTE prepared_custom_type_select_with_search_path('(1,1)');
count
---------------------------------------------------------------------
0
(1 row)
EXECUTE prepared_custom_type_select_with_search_path('(1,1)');
count
---------------------------------------------------------------------
0
(1 row)
EXECUTE prepared_custom_type_select_with_search_path('(1,1)');
count
---------------------------------------------------------------------
0
(1 row)
EXECUTE prepared_custom_type_select_with_search_path('(1,1)');
count
---------------------------------------------------------------------
0
(1 row)
EXECUTE prepared_custom_type_select_with_search_path('(1,1)');
count
---------------------------------------------------------------------
0
(1 row)
-- also show that it works even if we explicitly cast the type
EXECUTE prepared_custom_type_select_with_search_path('(1,1)'::public.test_composite_type);
count
---------------------------------------------------------------------
0
(1 row)
DROP SCHEMA internal_test_schema CASCADE;
SET search_path TO public;
SELECT * FROM router_executor_table ORDER BY comment; SELECT * FROM router_executor_table ORDER BY comment;
id | comment | stats id | comment | stats
--------------------------------------------------------------------- ---------------------------------------------------------------------

View File

@ -179,6 +179,41 @@ EXECUTE prepared_insert('comment-4', '(4, 40)');
EXECUTE prepared_insert('comment-5', '(5, 50)'); EXECUTE prepared_insert('comment-5', '(5, 50)');
EXECUTE prepared_insert('comment-6', '(6, 60)'); EXECUTE prepared_insert('comment-6', '(6, 60)');
-- to make this work, Citus adds the type casting for composite keys
-- during the deparsing
PREPARE prepared_custom_type_select(test_composite_type) AS
SELECT count(*) FROM router_executor_table WHERE id = 1 AND stats = $1;
EXECUTE prepared_custom_type_select('(1,1)');
EXECUTE prepared_custom_type_select('(1,1)');
EXECUTE prepared_custom_type_select('(1,1)');
EXECUTE prepared_custom_type_select('(1,1)');
EXECUTE prepared_custom_type_select('(1,1)');
EXECUTE prepared_custom_type_select('(1,1)');
EXECUTE prepared_custom_type_select('(1,1)');
CREATE SCHEMA internal_test_schema;
SET search_path TO internal_test_schema;
-- to make this work, Citus adds the type casting for composite keys
-- during the deparsing
PREPARE prepared_custom_type_select_with_search_path(public.test_composite_type) AS
SELECT count(*) FROM public.router_executor_table WHERE id = 1 AND stats = $1;
EXECUTE prepared_custom_type_select_with_search_path('(1,1)');
EXECUTE prepared_custom_type_select_with_search_path('(1,1)');
EXECUTE prepared_custom_type_select_with_search_path('(1,1)');
EXECUTE prepared_custom_type_select_with_search_path('(1,1)');
EXECUTE prepared_custom_type_select_with_search_path('(1,1)');
EXECUTE prepared_custom_type_select_with_search_path('(1,1)');
EXECUTE prepared_custom_type_select_with_search_path('(1,1)');
-- also show that it works even if we explicitly cast the type
EXECUTE prepared_custom_type_select_with_search_path('(1,1)'::public.test_composite_type);
DROP SCHEMA internal_test_schema CASCADE;
SET search_path TO public;
SELECT * FROM router_executor_table ORDER BY comment; SELECT * FROM router_executor_table ORDER BY comment;
-- test parameterized selects -- test parameterized selects