PostgreSQL Source Code git master
Loading...
Searching...
No Matches
test_custom_types.c
Go to the documentation of this file.
1/*--------------------------------------------------------------------------
2 *
3 * test_custom_types.c
4 * Test module for a set of functions for custom types.
5 *
6 * The custom type used in this module is similar to int4 for simplicity,
7 * except that it is able to use various typanalyze functions to enforce
8 * check patterns with ANALYZE.
9 *
10 * Copyright (c) 1996-2026, PostgreSQL Global Development Group
11 *
12 * IDENTIFICATION
13 * src/test/modules/test_custom_types/test_custom_types.c
14 *
15 *--------------------------------------------------------------------------
16 */
17
18#include "postgres.h"
19
20#include "fmgr.h"
21#include "commands/vacuum.h"
22#include "utils/builtins.h"
23
25
26/* Function declarations */
38
39/*
40 * int_custom_in - input function for int_custom type
41 *
42 * Converts a string to a int_custom (which is just an int32 internally).
43 */
46{
47 char *num = PG_GETARG_CSTRING(0);
48
49 PG_RETURN_INT32(pg_strtoint32_safe(num, fcinfo->context));
50}
51
52/*
53 * int_custom_out - output function for int_custom type
54 *
55 * Converts a int_custom to a string.
56 */
59{
61 char *result = (char *) palloc(12); /* sign, 10 digits, '\0' */
62
63 pg_ltoa(arg1, result);
64 PG_RETURN_CSTRING(result);
65}
66
67/*
68 * int_custom_typanalyze_false - typanalyze function that returns false
69 *
70 * This function returns false, to simulate a type that cannot be analyzed.
71 */
77
78/*
79 * Callback used to compute invalid statistics.
80 */
81static void
83 int samplerows, double totalrows)
84{
85 /* We are not valid, and do not want to be. */
86 stats->stats_valid = false;
87}
88
89/*
90 * int_custom_typanalyze_invalid
91 *
92 * This function sets some invalid stats data, letting the caller know that
93 * we are safe for an analyze, returning true.
94 */
97{
99
100 /* If the attstattarget column is negative, use the default value */
101 if (stats->attstattarget < 0)
103
104 /* Buggy number, no need to care as long as it is positive */
105 stats->minrows = 300;
106
107 /* Set callback to compute some invalid stats */
109
110 PG_RETURN_BOOL(true);
111}
112
113/*
114 * Comparison functions for int_custom type
115 */
116Datum
124
125Datum
133
134Datum
142
143Datum
151
152Datum
160
161Datum
169
170Datum
172{
175
176 if (arg1 < arg2)
177 PG_RETURN_INT32(-1);
178 else if (arg1 > arg2)
180 else
182}
int32_t int32
Definition c.h:575
int default_statistics_target
Definition analyze.c:70
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_RETURN_CSTRING(x)
Definition fmgr.h:364
#define PG_GETARG_CSTRING(n)
Definition fmgr.h:278
#define PG_FUNCTION_INFO_V1(funcname)
Definition fmgr.h:417
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
void * palloc(Size size)
Definition mcxt.c:1387
int pg_ltoa(int32 value, char *a)
Definition numutils.c:1119
int32 pg_strtoint32_safe(const char *s, Node *escontext)
Definition numutils.c:388
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
bool stats_valid
Definition vacuum.h:144
int minrows
Definition vacuum.h:137
int attstattarget
Definition vacuum.h:125
AnalyzeAttrComputeStatsFunc compute_stats
Definition vacuum.h:136
Datum int_custom_typanalyze_false(PG_FUNCTION_ARGS)
Datum int_custom_lt(PG_FUNCTION_ARGS)
Datum int_custom_in(PG_FUNCTION_ARGS)
Datum int_custom_cmp(PG_FUNCTION_ARGS)
PG_MODULE_MAGIC
Datum int_custom_gt(PG_FUNCTION_ARGS)
Datum int_custom_ne(PG_FUNCTION_ARGS)
Datum int_custom_typanalyze_invalid(PG_FUNCTION_ARGS)
Datum int_custom_ge(PG_FUNCTION_ARGS)
static void int_custom_invalid_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc, int samplerows, double totalrows)
Datum int_custom_eq(PG_FUNCTION_ARGS)
Datum int_custom_le(PG_FUNCTION_ARGS)
Datum int_custom_out(PG_FUNCTION_ARGS)
Datum(* AnalyzeAttrFetchFunc)(VacAttrStatsP stats, int rownum, bool *isNull)
Definition vacuum.h:108