Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* src/test/modules/test_custom_types/test_custom_types--1.0.sql */
 
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION test_custom_types" to load this file. \quit
 
--
-- Input/output functions for int_custom type
--
CREATE FUNCTION int_custom_in(cstring)
RETURNS int_custom
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
 
CREATE FUNCTION int_custom_out(int_custom)
RETURNS cstring
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
 
--
-- Typanalyze function that returns false
--
CREATE FUNCTION int_custom_typanalyze_false(internal)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
 
--
-- Typanalyze function that returns invalid stats
--
CREATE FUNCTION int_custom_typanalyze_invalid(internal)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
 
--
-- Typanalyze function that fails for a non-negative attstattarget
--
CREATE FUNCTION int_custom_typanalyze_false_target(internal)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
 
--
-- Typanalyze function that fails on its second non-negative attstattarget
--
CREATE FUNCTION int_custom_typanalyze_false_second(internal)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
 
--
-- The int_custom type definition
--
-- This type is identical to int4 in storage, and is used in subsequent
-- tests to have different properties.
--
CREATE TYPE int_custom (
  INPUT = int_custom_in,
  OUTPUT = int_custom_out,
  LIKE = int4
);
 
--
-- Comparison functions for int_custom
--
-- These are required to create a btree operator class, which is needed
-- for the type to be usable in extended statistics objects.
--
CREATE FUNCTION int_custom_eq(int_custom, int_custom)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
 
CREATE FUNCTION int_custom_ne(int_custom, int_custom)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
 
CREATE FUNCTION int_custom_lt(int_custom, int_custom)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
 
CREATE FUNCTION int_custom_le(int_custom, int_custom)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
 
CREATE FUNCTION int_custom_gt(int_custom, int_custom)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
 
CREATE FUNCTION int_custom_ge(int_custom, int_custom)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
 
CREATE FUNCTION int_custom_cmp(int_custom, int_custom)
RETURNS integer
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
 
-- Operators for int_custom, for btree operator class
CREATE OPERATOR = (
  LEFTARG = int_custom,
  RIGHTARG = int_custom,
  FUNCTION = int_custom_eq,
  COMMUTATOR = =,
  NEGATOR = <>,
  RESTRICT = eqsel,
  JOIN = eqjoinsel,
  HASHES,
  MERGES
);
 
CREATE OPERATOR <> (
  LEFTARG = int_custom,
  RIGHTARG = int_custom,
  FUNCTION = int_custom_ne,
  COMMUTATOR = <>,
  NEGATOR = =,
  RESTRICT = neqsel,
  JOIN = neqjoinsel
);
 
CREATE OPERATOR < (
  LEFTARG = int_custom,
  RIGHTARG = int_custom,
  FUNCTION = int_custom_lt,
  COMMUTATOR = >,
  NEGATOR = >=,
  RESTRICT = scalarltsel,
  JOIN = scalarltjoinsel
);
 
CREATE OPERATOR <= (
  LEFTARG = int_custom,
  RIGHTARG = int_custom,
  FUNCTION = int_custom_le,
  COMMUTATOR = >=,
  NEGATOR = >,
  RESTRICT = scalarlesel,
  JOIN = scalarlejoinsel
);
 
CREATE OPERATOR > (
  LEFTARG = int_custom,
  RIGHTARG = int_custom,
  FUNCTION = int_custom_gt,
  COMMUTATOR = <,
  NEGATOR = <=,
  RESTRICT = scalargtsel,
  JOIN = scalargtjoinsel
);
 
CREATE OPERATOR >= (
  LEFTARG = int_custom,
  RIGHTARG = int_custom,
  FUNCTION = int_custom_ge,
  COMMUTATOR = <=,
  NEGATOR = <,
  RESTRICT = scalargesel,
  JOIN = scalargejoinsel
);
 
--
-- Btree operator class for int_custom
--
-- This is required for the type to be usable in extended statistics objects,
-- for attributes and expressions.
--
CREATE OPERATOR CLASS int_custom_ops
  DEFAULT FOR TYPE int_custom USING btree AS
    OPERATOR    1     <,
    OPERATOR    2     <=,
    OPERATOR    3     =,
    OPERATOR    4     >=,
    OPERATOR    5     >,
    FUNCTION    1     int_custom_cmp(int_custom, int_custom);