diff --git a/configure b/configure index 65e89799f..73a841bee 100755 --- a/configure +++ b/configure @@ -6160,3 +6160,4 @@ if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi + diff --git a/src/backend/distributed/shared_library_init.c b/src/backend/distributed/shared_library_init.c index 4e0f9d0de..effd5dfdc 100644 --- a/src/backend/distributed/shared_library_init.c +++ b/src/backend/distributed/shared_library_init.c @@ -86,6 +86,7 @@ #include "distributed/remote_commands.h" #include "distributed/shard_rebalancer.h" #include "distributed/shared_library_init.h" +#include "distributed/smart_hint.h" #include "distributed/statistics_collection.h" #include "distributed/subplan_execution.h" #include "distributed/resource_lock.h" @@ -701,6 +702,8 @@ multi_log_hook(ErrorData *edata) "involved in a distributed deadlock"); } + ReplaceCitusHintSmart(edata); + if (original_emit_log_hook) { original_emit_log_hook(edata); diff --git a/src/backend/distributed/smart_hint.c b/src/backend/distributed/smart_hint.c new file mode 100644 index 000000000..da107c75c --- /dev/null +++ b/src/backend/distributed/smart_hint.c @@ -0,0 +1,8 @@ +#include "postgres.h" +#include "distributed/smart_hint.h" + +void +ReplaceCitusHintSmart(ErrorData *edata) +{ + edata->hint = pstrdup("Try to run the query with the smart hint"); +} diff --git a/src/backend/distributed/sql/citus--11.3-1--12.0-1.sql b/src/backend/distributed/sql/citus--11.3-1--12.0-1.sql index 56bbdfb0d..43bbcb181 100644 --- a/src/backend/distributed/sql/citus--11.3-1--12.0-1.sql +++ b/src/backend/distributed/sql/citus--11.3-1--12.0-1.sql @@ -1,3 +1,27 @@ -- citus--11.3-1--12.0-1 -- bump version to 12.0-1 + +CREATE OR REPLACE FUNCTION pg_catalog.get_cluster_stats() +RETURNS text +AS $$ +DECLARE + cluster_stats text; +BEGIN + WITH citus_tables_arr AS ( + SELECT array_agg(row_to_json(t.*)) d FROM public.citus_tables t + ), + citus_nodes_arr AS ( + SELECT array_agg(row_to_json(t.*)) d FROM pg_catalog.pg_dist_node t + ), + key_values AS ( + SELECT unnest(ARRAY['citus_tables', 'citus_nodes']) AS key, + unnest(ARRAY[to_json(citus_tables_arr.d), to_json(citus_nodes_arr.d)]::json[]) AS value + FROM citus_tables_arr, citus_nodes_arr + ) + SELECT json_object_agg(key, value)::text INTO cluster_stats + FROM key_values; + + RETURN cluster_stats; +END; +$$ LANGUAGE plpgsql; diff --git a/src/include/distributed/smart_hint.h b/src/include/distributed/smart_hint.h new file mode 100644 index 000000000..ce8da7492 --- /dev/null +++ b/src/include/distributed/smart_hint.h @@ -0,0 +1,9 @@ + +#ifndef DISTRIBUTED_SMART_HINT_H +#define DISTRIBUTED_SMART_HINT_H + +#include "postgres.h" + +extern void ReplaceCitusHintSmart(ErrorData *edata); + +#endif /* DISTRIBUTED_SMART_HINT_H */