mirror of
https://github.com/postgres/postgres.git
synced 2025-11-15 03:41:20 +03:00
Move code specific to pg_dependencies to new file
This new file is named pg_dependencies.c and includes all the code directly related to the data type pg_dependencies, extracted from the extended statistics code. Some patches are under discussion to change its input and output functions, and this separation makes the follow-up changes cleaner by separating the logic related to the data type and the functional dependencies statistics core logic in dependencies.c. Author: Corey Huinker <corey.huinker@gmail.com> Co-authored-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/aQ2k8--a0FfwSwX9@paquier.xyz
This commit is contained in:
@@ -16,23 +16,17 @@
|
|||||||
#include "access/htup_details.h"
|
#include "access/htup_details.h"
|
||||||
#include "catalog/pg_statistic_ext.h"
|
#include "catalog/pg_statistic_ext.h"
|
||||||
#include "catalog/pg_statistic_ext_data.h"
|
#include "catalog/pg_statistic_ext_data.h"
|
||||||
#include "lib/stringinfo.h"
|
|
||||||
#include "nodes/nodeFuncs.h"
|
#include "nodes/nodeFuncs.h"
|
||||||
#include "nodes/nodes.h"
|
|
||||||
#include "nodes/pathnodes.h"
|
|
||||||
#include "optimizer/clauses.h"
|
#include "optimizer/clauses.h"
|
||||||
#include "optimizer/optimizer.h"
|
#include "optimizer/optimizer.h"
|
||||||
#include "parser/parsetree.h"
|
#include "parser/parsetree.h"
|
||||||
#include "statistics/extended_stats_internal.h"
|
#include "statistics/extended_stats_internal.h"
|
||||||
#include "statistics/statistics.h"
|
|
||||||
#include "utils/fmgroids.h"
|
#include "utils/fmgroids.h"
|
||||||
#include "utils/fmgrprotos.h"
|
|
||||||
#include "utils/lsyscache.h"
|
#include "utils/lsyscache.h"
|
||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
#include "utils/selfuncs.h"
|
#include "utils/selfuncs.h"
|
||||||
#include "utils/syscache.h"
|
#include "utils/syscache.h"
|
||||||
#include "utils/typcache.h"
|
#include "utils/typcache.h"
|
||||||
#include "varatt.h"
|
|
||||||
|
|
||||||
/* size of the struct header fields (magic, type, ndeps) */
|
/* size of the struct header fields (magic, type, ndeps) */
|
||||||
#define SizeOfHeader (3 * sizeof(uint32))
|
#define SizeOfHeader (3 * sizeof(uint32))
|
||||||
@@ -643,91 +637,6 @@ statext_dependencies_load(Oid mvoid, bool inh)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* pg_dependencies_in - input routine for type pg_dependencies.
|
|
||||||
*
|
|
||||||
* pg_dependencies is real enough to be a table column, but it has no operations
|
|
||||||
* of its own, and disallows input too
|
|
||||||
*/
|
|
||||||
Datum
|
|
||||||
pg_dependencies_in(PG_FUNCTION_ARGS)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* pg_node_list stores the data in binary form and parsing text input is
|
|
||||||
* not needed, so disallow this.
|
|
||||||
*/
|
|
||||||
ereport(ERROR,
|
|
||||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
||||||
errmsg("cannot accept a value of type %s", "pg_dependencies")));
|
|
||||||
|
|
||||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* pg_dependencies - output routine for type pg_dependencies.
|
|
||||||
*/
|
|
||||||
Datum
|
|
||||||
pg_dependencies_out(PG_FUNCTION_ARGS)
|
|
||||||
{
|
|
||||||
bytea *data = PG_GETARG_BYTEA_PP(0);
|
|
||||||
MVDependencies *dependencies = statext_dependencies_deserialize(data);
|
|
||||||
int i,
|
|
||||||
j;
|
|
||||||
StringInfoData str;
|
|
||||||
|
|
||||||
initStringInfo(&str);
|
|
||||||
appendStringInfoChar(&str, '{');
|
|
||||||
|
|
||||||
for (i = 0; i < dependencies->ndeps; i++)
|
|
||||||
{
|
|
||||||
MVDependency *dependency = dependencies->deps[i];
|
|
||||||
|
|
||||||
if (i > 0)
|
|
||||||
appendStringInfoString(&str, ", ");
|
|
||||||
|
|
||||||
appendStringInfoChar(&str, '"');
|
|
||||||
for (j = 0; j < dependency->nattributes; j++)
|
|
||||||
{
|
|
||||||
if (j == dependency->nattributes - 1)
|
|
||||||
appendStringInfoString(&str, " => ");
|
|
||||||
else if (j > 0)
|
|
||||||
appendStringInfoString(&str, ", ");
|
|
||||||
|
|
||||||
appendStringInfo(&str, "%d", dependency->attributes[j]);
|
|
||||||
}
|
|
||||||
appendStringInfo(&str, "\": %f", dependency->degree);
|
|
||||||
}
|
|
||||||
|
|
||||||
appendStringInfoChar(&str, '}');
|
|
||||||
|
|
||||||
PG_RETURN_CSTRING(str.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* pg_dependencies_recv - binary input routine for type pg_dependencies.
|
|
||||||
*/
|
|
||||||
Datum
|
|
||||||
pg_dependencies_recv(PG_FUNCTION_ARGS)
|
|
||||||
{
|
|
||||||
ereport(ERROR,
|
|
||||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
||||||
errmsg("cannot accept a value of type %s", "pg_dependencies")));
|
|
||||||
|
|
||||||
PG_RETURN_VOID(); /* keep compiler quiet */
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* pg_dependencies_send - binary output routine for type pg_dependencies.
|
|
||||||
*
|
|
||||||
* Functional dependencies are serialized in a bytea value (although the type
|
|
||||||
* is named differently), so let's just send that.
|
|
||||||
*/
|
|
||||||
Datum
|
|
||||||
pg_dependencies_send(PG_FUNCTION_ARGS)
|
|
||||||
{
|
|
||||||
return byteasend(fcinfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* dependency_is_compatible_clause
|
* dependency_is_compatible_clause
|
||||||
* Determines if the clause is compatible with functional dependencies
|
* Determines if the clause is compatible with functional dependencies
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ OBJS = \
|
|||||||
oracle_compat.o \
|
oracle_compat.o \
|
||||||
orderedsetaggs.o \
|
orderedsetaggs.o \
|
||||||
partitionfuncs.o \
|
partitionfuncs.o \
|
||||||
|
pg_dependencies.o \
|
||||||
pg_locale.o \
|
pg_locale.o \
|
||||||
pg_locale_builtin.o \
|
pg_locale_builtin.o \
|
||||||
pg_locale_icu.o \
|
pg_locale_icu.o \
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ backend_sources += files(
|
|||||||
'oracle_compat.c',
|
'oracle_compat.c',
|
||||||
'orderedsetaggs.c',
|
'orderedsetaggs.c',
|
||||||
'partitionfuncs.c',
|
'partitionfuncs.c',
|
||||||
|
'pg_dependencies.c',
|
||||||
'pg_locale.c',
|
'pg_locale.c',
|
||||||
'pg_locale_builtin.c',
|
'pg_locale_builtin.c',
|
||||||
'pg_locale_icu.c',
|
'pg_locale_icu.c',
|
||||||
|
|||||||
104
src/backend/utils/adt/pg_dependencies.c
Normal file
104
src/backend/utils/adt/pg_dependencies.c
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* pg_dependencies.c
|
||||||
|
* pg_dependencies data type support.
|
||||||
|
*
|
||||||
|
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
||||||
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
|
*
|
||||||
|
* IDENTIFICATION
|
||||||
|
* src/backend/utils/adt/pg_dependencies.c
|
||||||
|
*
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "postgres.h"
|
||||||
|
|
||||||
|
#include "lib/stringinfo.h"
|
||||||
|
#include "statistics/extended_stats_internal.h"
|
||||||
|
#include "utils/fmgrprotos.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pg_dependencies_in - input routine for type pg_dependencies.
|
||||||
|
*
|
||||||
|
* pg_dependencies is real enough to be a table column, but it has no operations
|
||||||
|
* of its own, and disallows input too
|
||||||
|
*/
|
||||||
|
Datum
|
||||||
|
pg_dependencies_in(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* pg_node_list stores the data in binary form and parsing text input is
|
||||||
|
* not needed, so disallow this.
|
||||||
|
*/
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
|
errmsg("cannot accept a value of type %s", "pg_dependencies")));
|
||||||
|
|
||||||
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pg_dependencies - output routine for type pg_dependencies.
|
||||||
|
*/
|
||||||
|
Datum
|
||||||
|
pg_dependencies_out(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
|
bytea *data = PG_GETARG_BYTEA_PP(0);
|
||||||
|
MVDependencies *dependencies = statext_dependencies_deserialize(data);
|
||||||
|
int i,
|
||||||
|
j;
|
||||||
|
StringInfoData str;
|
||||||
|
|
||||||
|
initStringInfo(&str);
|
||||||
|
appendStringInfoChar(&str, '{');
|
||||||
|
|
||||||
|
for (i = 0; i < dependencies->ndeps; i++)
|
||||||
|
{
|
||||||
|
MVDependency *dependency = dependencies->deps[i];
|
||||||
|
|
||||||
|
if (i > 0)
|
||||||
|
appendStringInfoString(&str, ", ");
|
||||||
|
|
||||||
|
appendStringInfoChar(&str, '"');
|
||||||
|
for (j = 0; j < dependency->nattributes; j++)
|
||||||
|
{
|
||||||
|
if (j == dependency->nattributes - 1)
|
||||||
|
appendStringInfoString(&str, " => ");
|
||||||
|
else if (j > 0)
|
||||||
|
appendStringInfoString(&str, ", ");
|
||||||
|
|
||||||
|
appendStringInfo(&str, "%d", dependency->attributes[j]);
|
||||||
|
}
|
||||||
|
appendStringInfo(&str, "\": %f", dependency->degree);
|
||||||
|
}
|
||||||
|
|
||||||
|
appendStringInfoChar(&str, '}');
|
||||||
|
|
||||||
|
PG_RETURN_CSTRING(str.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pg_dependencies_recv - binary input routine for type pg_dependencies.
|
||||||
|
*/
|
||||||
|
Datum
|
||||||
|
pg_dependencies_recv(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
|
errmsg("cannot accept a value of type %s", "pg_dependencies")));
|
||||||
|
|
||||||
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pg_dependencies_send - binary output routine for type pg_dependencies.
|
||||||
|
*
|
||||||
|
* Functional dependencies are serialized in a bytea value (although the type
|
||||||
|
* is named differently), so let's just send that.
|
||||||
|
*/
|
||||||
|
Datum
|
||||||
|
pg_dependencies_send(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
|
return byteasend(fcinfo);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user