globegit-postgresql-plruby 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/Changes +121 -0
  2. data/README.markdown +155 -0
  3. data/Rakefile +48 -0
  4. data/docs/plruby.rb +1931 -0
  5. data/ex_trans.sql +33 -0
  6. data/extconf.rb +267 -0
  7. data/plruby.html +1454 -0
  8. data/plruby.rd +1571 -0
  9. data/postgresql-plruby.gemspec +56 -0
  10. data/src/conversions.h +5 -0
  11. data/src/conversions/basic/conversions.h +25 -0
  12. data/src/conversions/basic/extconf.rb +8 -0
  13. data/src/conversions/basic/plruby_basic.c +357 -0
  14. data/src/conversions/bitstring/bitstring.sql +75 -0
  15. data/src/conversions/bitstring/conversions.h +15 -0
  16. data/src/conversions/bitstring/extconf.rb +8 -0
  17. data/src/conversions/bitstring/plruby_bitstring.c +579 -0
  18. data/src/conversions/convcommon.h +129 -0
  19. data/src/conversions/datetime/conversions.h +13 -0
  20. data/src/conversions/datetime/extconf.rb +8 -0
  21. data/src/conversions/datetime/plruby_datetime.c +269 -0
  22. data/src/conversions/geometry/conversions.h +37 -0
  23. data/src/conversions/geometry/extconf.rb +8 -0
  24. data/src/conversions/geometry/geometry.sql +196 -0
  25. data/src/conversions/geometry/plruby_geometry.c +2494 -0
  26. data/src/conversions/network/conversions.h +21 -0
  27. data/src/conversions/network/extconf.rb +8 -0
  28. data/src/conversions/network/network.sql +63 -0
  29. data/src/conversions/network/plruby_network.c +537 -0
  30. data/src/package.h +20 -0
  31. data/src/plpl.c +1708 -0
  32. data/src/plplan.c +893 -0
  33. data/src/plruby.c +1676 -0
  34. data/src/plruby.h +324 -0
  35. data/src/pltrans.c +388 -0
  36. data/test/conv_bitstring/b.rb +45 -0
  37. data/test/conv_bitstring/runtest +26 -0
  38. data/test/conv_bitstring/test.expected.73 +148 -0
  39. data/test/conv_bitstring/test.expected.74 +148 -0
  40. data/test/conv_bitstring/test.expected.80 +148 -0
  41. data/test/conv_bitstring/test.expected.81 +148 -0
  42. data/test/conv_bitstring/test.expected.82 +148 -0
  43. data/test/conv_bitstring/test.expected.83 +148 -0
  44. data/test/conv_bitstring/test.expected.84 +148 -0
  45. data/test/conv_bitstring/test.out +148 -0
  46. data/test/conv_bitstring/test_mklang.sql +8 -0
  47. data/test/conv_bitstring/test_queries.sql +63 -0
  48. data/test/conv_bitstring/test_queries.sql.in +63 -0
  49. data/test/conv_geometry/b.rb +45 -0
  50. data/test/conv_geometry/runtest +26 -0
  51. data/test/conv_geometry/test.expected.73 +265 -0
  52. data/test/conv_geometry/test.expected.74 +265 -0
  53. data/test/conv_geometry/test.expected.80 +265 -0
  54. data/test/conv_geometry/test.expected.81 +265 -0
  55. data/test/conv_geometry/test.expected.82 +265 -0
  56. data/test/conv_geometry/test.expected.83 +265 -0
  57. data/test/conv_geometry/test.expected.84 +265 -0
  58. data/test/conv_geometry/test.out +265 -0
  59. data/test/conv_geometry/test_mklang.sql +8 -0
  60. data/test/conv_geometry/test_queries.sql +194 -0
  61. data/test/conv_geometry/test_queries.sql.in +194 -0
  62. data/test/conv_network/b.rb +45 -0
  63. data/test/conv_network/runtest +26 -0
  64. data/test/conv_network/test.expected.73 +213 -0
  65. data/test/conv_network/test.expected.74 +237 -0
  66. data/test/conv_network/test.expected.80 +237 -0
  67. data/test/conv_network/test.expected.81 +237 -0
  68. data/test/conv_network/test.expected.82 +237 -0
  69. data/test/conv_network/test.expected.83 +237 -0
  70. data/test/conv_network/test.expected.84 +237 -0
  71. data/test/conv_network/test.out +237 -0
  72. data/test/conv_network/test_mklang.sql +8 -0
  73. data/test/conv_network/test_queries.sql +60 -0
  74. data/test/conv_network/test_queries.sql.in +60 -0
  75. data/test/plp/b.rb +34 -0
  76. data/test/plp/runtest +29 -0
  77. data/test/plp/test.expected.73 +472 -0
  78. data/test/plp/test.expected.74 +472 -0
  79. data/test/plp/test.expected.75 +472 -0
  80. data/test/plp/test.expected.80 +472 -0
  81. data/test/plp/test.expected.81 +472 -0
  82. data/test/plp/test.expected.82 +472 -0
  83. data/test/plp/test.expected.83 +472 -0
  84. data/test/plp/test.expected.84 +472 -0
  85. data/test/plp/test.out +472 -0
  86. data/test/plp/test_mklang.sql +8 -0
  87. data/test/plp/test_queries.sql +273 -0
  88. data/test/plp/test_setup.sql +931 -0
  89. data/test/plp/test_setup.sql.in +931 -0
  90. data/test/plt/b.rb +34 -0
  91. data/test/plt/runtest +29 -0
  92. data/test/plt/test.expected.73 +178 -0
  93. data/test/plt/test.expected.74 +178 -0
  94. data/test/plt/test.expected.75 +178 -0
  95. data/test/plt/test.expected.80 +178 -0
  96. data/test/plt/test.expected.81 +178 -0
  97. data/test/plt/test.expected.82 +178 -0
  98. data/test/plt/test.expected.83 +164 -0
  99. data/test/plt/test.expected.84 +168 -0
  100. data/test/plt/test.out +168 -0
  101. data/test/plt/test_mklang.sql +8 -0
  102. data/test/plt/test_queries.sql +72 -0
  103. data/test/plt/test_setup.sql +252 -0
  104. data/test/plt/test_setup.sql.in +252 -0
  105. data/test/range/b.rb +45 -0
  106. data/test/range/runtest +26 -0
  107. data/test/range/test.expected.73 +396 -0
  108. data/test/range/test.expected.73.in +396 -0
  109. data/test/range/test.expected.74 +396 -0
  110. data/test/range/test.expected.74.in +396 -0
  111. data/test/range/test.expected.75 +396 -0
  112. data/test/range/test.expected.75.in +396 -0
  113. data/test/range/test.expected.80 +396 -0
  114. data/test/range/test.expected.81 +397 -0
  115. data/test/range/test.expected.82 +397 -0
  116. data/test/range/test.expected.83 +397 -0
  117. data/test/range/test.expected.84 +399 -0
  118. data/test/range/test.out +399 -0
  119. data/test/range/test_mklang.sql +8 -0
  120. data/test/range/test_queries.sql +249 -0
  121. data/test/range/test_queries.sql.in +249 -0
  122. metadata +207 -0
@@ -0,0 +1,397 @@
1
+ SELECT * FROM pg_settings WHERE name LIKE 'enable%';
2
+ name | setting | unit | category | short_desc | extra_desc | context | vartype | source | min_val | max_val
3
+ -------------------+---------+------+---------------------------------------------+--------------------------------------------------------+------------+---------+---------+---------+---------+---------
4
+ enable_bitmapscan | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of bitmap-scan plans. | | user | bool | default | |
5
+ enable_hashagg | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of hashed aggregation plans. | | user | bool | default | |
6
+ enable_hashjoin | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of hash join plans. | | user | bool | default | |
7
+ enable_indexscan | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of index-scan plans. | | user | bool | default | |
8
+ enable_mergejoin | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of merge join plans. | | user | bool | default | |
9
+ enable_nestloop | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of nested-loop join plans. | | user | bool | default | |
10
+ enable_seqscan | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of sequential-scan plans. | | user | bool | default | |
11
+ enable_sort | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of explicit sort steps. | | user | bool | default | |
12
+ enable_tidscan | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of TID scan plans. | | user | bool | default | |
13
+ (9 rows)
14
+
15
+ CREATE TABLE foo2(fooid int, f2 int);
16
+ INSERT INTO foo2 VALUES(1, 11);
17
+ INSERT INTO foo2 VALUES(2, 22);
18
+ INSERT INTO foo2 VALUES(1, 111);
19
+ CREATE FUNCTION foot(int) returns setof foo2 as '
20
+ "SELECT * FROM foo2 WHERE fooid = #{args[0]}"'
21
+ language 'plruby';
22
+ select * from foo2, foot(foo2.fooid) z where foo2.f2 = z.f2;
23
+ ERROR: function expression in FROM cannot refer to other relations of same query level
24
+ select * from foo2 where f2 in (
25
+ select f2 from foot(foo2.fooid) z where z.fooid = foo2.fooid
26
+ ) ORDER BY 1,2;
27
+ fooid | f2
28
+ -------+-----
29
+ 1 | 11
30
+ 1 | 111
31
+ 2 | 22
32
+ (3 rows)
33
+
34
+ select * from foo2 where f2 in (
35
+ select f2 from foot(1) z where z.fooid = foo2.fooid
36
+ ) ORDER BY 1,2;
37
+ fooid | f2
38
+ -------+-----
39
+ 1 | 11
40
+ 1 | 111
41
+ (2 rows)
42
+
43
+ select * from foo2 where f2 in (
44
+ select f2 from foot(foo2.fooid) z where z.fooid = 1
45
+ ) ORDER BY 1,2;
46
+ fooid | f2
47
+ -------+-----
48
+ 1 | 11
49
+ 1 | 111
50
+ (2 rows)
51
+
52
+ select foot.fooid, foot.f2 from foot(sin(pi()/2)::int) ORDER BY 1,2;
53
+ fooid | f2
54
+ -------+-----
55
+ 1 | 11
56
+ 1 | 111
57
+ (2 rows)
58
+
59
+ CREATE TABLE foo (fooid int, foosubid int, fooname text, primary key(fooid,foosubid));
60
+ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo"
61
+ INSERT INTO foo VALUES(1,1,'Joe');
62
+ INSERT INTO foo VALUES(1,2,'Ed');
63
+ INSERT INTO foo VALUES(2,1,'Mary');
64
+ CREATE FUNCTION getfoo(int) RETURNS int AS '
65
+ args[0]
66
+ ' language 'plruby';
67
+ SELECT * FROM getfoo(1) AS t1;
68
+ t1
69
+ ----
70
+ 1
71
+ (1 row)
72
+
73
+ CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
74
+ SELECT * FROM vw_getfoo;
75
+ getfoo
76
+ --------
77
+ 1
78
+ (1 row)
79
+
80
+ DROP VIEW vw_getfoo;
81
+ DROP FUNCTION getfoo(int);
82
+ CREATE FUNCTION getfoo(int) RETURNS setof int AS '
83
+ "SELECT fooid FROM foo WHERE fooid = #{args[0]}"
84
+ ' language 'plruby';
85
+ SELECT * FROM getfoo(1) AS t1;
86
+ t1
87
+ ----
88
+ 1
89
+ 1
90
+ (2 rows)
91
+
92
+ CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
93
+ SELECT * FROM vw_getfoo;
94
+ getfoo
95
+ --------
96
+ 1
97
+ 1
98
+ (2 rows)
99
+
100
+ DROP VIEW vw_getfoo;
101
+ DROP FUNCTION getfoo(int);
102
+ CREATE FUNCTION getfoo(int) RETURNS setof text AS '
103
+ "SELECT fooname FROM foo WHERE fooid = #{args[0]}"
104
+ ' language 'plruby';
105
+ SELECT * FROM getfoo(1) AS t1;
106
+ t1
107
+ -----
108
+ Joe
109
+ Ed
110
+ (2 rows)
111
+
112
+ CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
113
+ SELECT * FROM vw_getfoo;
114
+ getfoo
115
+ --------
116
+ Joe
117
+ Ed
118
+ (2 rows)
119
+
120
+ DROP VIEW vw_getfoo;
121
+ DROP FUNCTION getfoo(int);
122
+ CREATE FUNCTION getfoo(int) RETURNS setof foo AS '
123
+ "SELECT * FROM foo WHERE fooid = #{args[0]}"
124
+ ' language 'plruby';
125
+ SELECT * FROM getfoo(1) AS t1;
126
+ fooid | foosubid | fooname
127
+ -------+----------+---------
128
+ 1 | 1 | Joe
129
+ 1 | 2 | Ed
130
+ (2 rows)
131
+
132
+ CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
133
+ SELECT * FROM vw_getfoo;
134
+ fooid | foosubid | fooname
135
+ -------+----------+---------
136
+ 1 | 1 | Joe
137
+ 1 | 2 | Ed
138
+ (2 rows)
139
+
140
+ DROP VIEW vw_getfoo;
141
+ DROP FUNCTION getfoo(int);
142
+ CREATE FUNCTION getfoo(int) RETURNS setof record AS '
143
+ "SELECT * FROM foo WHERE fooid = #{args[0]}"
144
+ ' language 'plruby';
145
+ SELECT * FROM getfoo(1) AS t1(fooid int, foosubid int, fooname text);
146
+ fooid | foosubid | fooname
147
+ -------+----------+---------
148
+ 1 | 1 | Joe
149
+ 1 | 2 | Ed
150
+ (2 rows)
151
+
152
+ CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1) AS (fooid int, foosubid int, fooname text);
153
+ SELECT * FROM vw_getfoo;
154
+ fooid | foosubid | fooname
155
+ -------+----------+---------
156
+ 1 | 1 | Joe
157
+ 1 | 2 | Ed
158
+ (2 rows)
159
+
160
+ DROP VIEW vw_getfoo;
161
+ DROP FUNCTION getfoo(int);
162
+ CREATE FUNCTION getfoo(int) RETURNS setof int AS '
163
+ PL.exec("SELECT fooid FROM foo WHERE fooid = #{args[0]}") do |row|
164
+ yield row.values
165
+ end
166
+ ' language 'plruby';
167
+ SELECT * FROM getfoo(1) AS t1;
168
+ t1
169
+ ----
170
+ 1
171
+ 1
172
+ (2 rows)
173
+
174
+ CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
175
+ SELECT * FROM vw_getfoo;
176
+ getfoo
177
+ --------
178
+ 1
179
+ 1
180
+ (2 rows)
181
+
182
+ DROP VIEW vw_getfoo;
183
+ DROP FUNCTION getfoo(int);
184
+ CREATE FUNCTION getfoo(int) RETURNS setof foo AS '
185
+ PL.exec("SELECT * FROM foo WHERE fooid = #{args[0]}", nil, "value") do |r|
186
+ yield r
187
+ end
188
+ ' language 'plruby';
189
+ SELECT * FROM getfoo(1) AS t1;
190
+ fooid | foosubid | fooname
191
+ -------+----------+---------
192
+ 1 | 1 | Joe
193
+ 1 | 2 | Ed
194
+ (2 rows)
195
+
196
+ CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
197
+ SELECT * FROM vw_getfoo;
198
+ fooid | foosubid | fooname
199
+ -------+----------+---------
200
+ 1 | 1 | Joe
201
+ 1 | 2 | Ed
202
+ (2 rows)
203
+
204
+ DROP VIEW vw_getfoo;
205
+ DROP FUNCTION getfoo(int);
206
+ DROP FUNCTION foot(int);
207
+ DROP TABLE foo2;
208
+ DROP TABLE foo;
209
+ CREATE TABLE foorescan (fooid int, foosubid int, fooname text, primary key(fooid,foosubid));
210
+ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foorescan_pkey" for table "foorescan"
211
+ INSERT INTO foorescan values(5000,1,'abc.5000.1');
212
+ INSERT INTO foorescan values(5001,1,'abc.5001.1');
213
+ INSERT INTO foorescan values(5002,1,'abc.5002.1');
214
+ INSERT INTO foorescan values(5003,1,'abc.5003.1');
215
+ INSERT INTO foorescan values(5004,1,'abc.5004.1');
216
+ INSERT INTO foorescan values(5005,1,'abc.5005.1');
217
+ INSERT INTO foorescan values(5006,1,'abc.5006.1');
218
+ INSERT INTO foorescan values(5007,1,'abc.5007.1');
219
+ INSERT INTO foorescan values(5008,1,'abc.5008.1');
220
+ INSERT INTO foorescan values(5009,1,'abc.5009.1');
221
+ INSERT INTO foorescan values(5000,2,'abc.5000.2');
222
+ INSERT INTO foorescan values(5001,2,'abc.5001.2');
223
+ INSERT INTO foorescan values(5002,2,'abc.5002.2');
224
+ INSERT INTO foorescan values(5003,2,'abc.5003.2');
225
+ INSERT INTO foorescan values(5004,2,'abc.5004.2');
226
+ INSERT INTO foorescan values(5005,2,'abc.5005.2');
227
+ INSERT INTO foorescan values(5006,2,'abc.5006.2');
228
+ INSERT INTO foorescan values(5007,2,'abc.5007.2');
229
+ INSERT INTO foorescan values(5008,2,'abc.5008.2');
230
+ INSERT INTO foorescan values(5009,2,'abc.5009.2');
231
+ INSERT INTO foorescan values(5000,3,'abc.5000.3');
232
+ INSERT INTO foorescan values(5001,3,'abc.5001.3');
233
+ INSERT INTO foorescan values(5002,3,'abc.5002.3');
234
+ INSERT INTO foorescan values(5003,3,'abc.5003.3');
235
+ INSERT INTO foorescan values(5004,3,'abc.5004.3');
236
+ INSERT INTO foorescan values(5005,3,'abc.5005.3');
237
+ INSERT INTO foorescan values(5006,3,'abc.5006.3');
238
+ INSERT INTO foorescan values(5007,3,'abc.5007.3');
239
+ INSERT INTO foorescan values(5008,3,'abc.5008.3');
240
+ INSERT INTO foorescan values(5009,3,'abc.5009.3');
241
+ INSERT INTO foorescan values(5000,4,'abc.5000.4');
242
+ INSERT INTO foorescan values(5001,4,'abc.5001.4');
243
+ INSERT INTO foorescan values(5002,4,'abc.5002.4');
244
+ INSERT INTO foorescan values(5003,4,'abc.5003.4');
245
+ INSERT INTO foorescan values(5004,4,'abc.5004.4');
246
+ INSERT INTO foorescan values(5005,4,'abc.5005.4');
247
+ INSERT INTO foorescan values(5006,4,'abc.5006.4');
248
+ INSERT INTO foorescan values(5007,4,'abc.5007.4');
249
+ INSERT INTO foorescan values(5008,4,'abc.5008.4');
250
+ INSERT INTO foorescan values(5009,4,'abc.5009.4');
251
+ INSERT INTO foorescan values(5000,5,'abc.5000.5');
252
+ INSERT INTO foorescan values(5001,5,'abc.5001.5');
253
+ INSERT INTO foorescan values(5002,5,'abc.5002.5');
254
+ INSERT INTO foorescan values(5003,5,'abc.5003.5');
255
+ INSERT INTO foorescan values(5004,5,'abc.5004.5');
256
+ INSERT INTO foorescan values(5005,5,'abc.5005.5');
257
+ INSERT INTO foorescan values(5006,5,'abc.5006.5');
258
+ INSERT INTO foorescan values(5007,5,'abc.5007.5');
259
+ INSERT INTO foorescan values(5008,5,'abc.5008.5');
260
+ INSERT INTO foorescan values(5009,5,'abc.5009.5');
261
+ CREATE FUNCTION foorescan(int,int) RETURNS setof foorescan AS '
262
+ "SELECT * FROM foorescan WHERE fooid >= #{args[0]} and fooid < #{args[1]}"
263
+ ' language 'plruby';
264
+ SELECT * FROM foorescan f WHERE f.fooid IN (
265
+ SELECT fooid FROM foorescan(5002,5004)
266
+ ) ORDER BY 1,2;
267
+ fooid | foosubid | fooname
268
+ -------+----------+------------
269
+ 5002 | 1 | abc.5002.1
270
+ 5002 | 2 | abc.5002.2
271
+ 5002 | 3 | abc.5002.3
272
+ 5002 | 4 | abc.5002.4
273
+ 5002 | 5 | abc.5002.5
274
+ 5003 | 1 | abc.5003.1
275
+ 5003 | 2 | abc.5003.2
276
+ 5003 | 3 | abc.5003.3
277
+ 5003 | 4 | abc.5003.4
278
+ 5003 | 5 | abc.5003.5
279
+ (10 rows)
280
+
281
+ CREATE VIEW vw_foorescan AS SELECT * FROM foorescan(5002,5004);
282
+ SELECT * FROM foorescan f WHERE f.fooid IN (
283
+ SELECT fooid FROM vw_foorescan
284
+ ) ORDER BY 1,2;
285
+ fooid | foosubid | fooname
286
+ -------+----------+------------
287
+ 5002 | 1 | abc.5002.1
288
+ 5002 | 2 | abc.5002.2
289
+ 5002 | 3 | abc.5002.3
290
+ 5002 | 4 | abc.5002.4
291
+ 5002 | 5 | abc.5002.5
292
+ 5003 | 1 | abc.5003.1
293
+ 5003 | 2 | abc.5003.2
294
+ 5003 | 3 | abc.5003.3
295
+ 5003 | 4 | abc.5003.4
296
+ 5003 | 5 | abc.5003.5
297
+ (10 rows)
298
+
299
+ CREATE TABLE barrescan (fooid int primary key);
300
+ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "barrescan_pkey" for table "barrescan"
301
+ INSERT INTO barrescan values(5003);
302
+ INSERT INTO barrescan values(5004);
303
+ INSERT INTO barrescan values(5005);
304
+ INSERT INTO barrescan values(5006);
305
+ INSERT INTO barrescan values(5007);
306
+ INSERT INTO barrescan values(5008);
307
+ CREATE FUNCTION foorescan(int) RETURNS setof foorescan AS '
308
+ "SELECT * FROM foorescan WHERE fooid = #{args[0]}"
309
+ ' language 'plruby';
310
+ SELECT f.* FROM barrescan b, foorescan f
311
+ WHERE f.fooid = b.fooid AND b.fooid IN (
312
+ SELECT fooid FROM foorescan(b.fooid)
313
+ ) ORDER BY 1,2;
314
+ fooid | foosubid | fooname
315
+ -------+----------+------------
316
+ 5003 | 1 | abc.5003.1
317
+ 5003 | 2 | abc.5003.2
318
+ 5003 | 3 | abc.5003.3
319
+ 5003 | 4 | abc.5003.4
320
+ 5003 | 5 | abc.5003.5
321
+ 5004 | 1 | abc.5004.1
322
+ 5004 | 2 | abc.5004.2
323
+ 5004 | 3 | abc.5004.3
324
+ 5004 | 4 | abc.5004.4
325
+ 5004 | 5 | abc.5004.5
326
+ 5005 | 1 | abc.5005.1
327
+ 5005 | 2 | abc.5005.2
328
+ 5005 | 3 | abc.5005.3
329
+ 5005 | 4 | abc.5005.4
330
+ 5005 | 5 | abc.5005.5
331
+ 5006 | 1 | abc.5006.1
332
+ 5006 | 2 | abc.5006.2
333
+ 5006 | 3 | abc.5006.3
334
+ 5006 | 4 | abc.5006.4
335
+ 5006 | 5 | abc.5006.5
336
+ 5007 | 1 | abc.5007.1
337
+ 5007 | 2 | abc.5007.2
338
+ 5007 | 3 | abc.5007.3
339
+ 5007 | 4 | abc.5007.4
340
+ 5007 | 5 | abc.5007.5
341
+ 5008 | 1 | abc.5008.1
342
+ 5008 | 2 | abc.5008.2
343
+ 5008 | 3 | abc.5008.3
344
+ 5008 | 4 | abc.5008.4
345
+ 5008 | 5 | abc.5008.5
346
+ (30 rows)
347
+
348
+ SELECT b.fooid, max(f.foosubid) FROM barrescan b, foorescan f
349
+ WHERE f.fooid = b.fooid AND b.fooid IN (
350
+ SELECT fooid FROM foorescan(b.fooid)
351
+ ) GROUP BY b.fooid ORDER BY 1,2;
352
+ fooid | max
353
+ -------+-----
354
+ 5003 | 5
355
+ 5004 | 5
356
+ 5005 | 5
357
+ 5006 | 5
358
+ 5007 | 5
359
+ 5008 | 5
360
+ (6 rows)
361
+
362
+ CREATE VIEW fooview1 AS SELECT f.* FROM barrescan b, foorescan f
363
+ WHERE f.fooid = b.fooid AND b.fooid IN (
364
+ SELECT fooid FROM foorescan(b.fooid)
365
+ ) ORDER BY 1,2;
366
+ SELECT * FROM fooview1 AS fv WHERE fv.fooid = 5004;
367
+ fooid | foosubid | fooname
368
+ -------+----------+------------
369
+ 5004 | 1 | abc.5004.1
370
+ 5004 | 2 | abc.5004.2
371
+ 5004 | 3 | abc.5004.3
372
+ 5004 | 4 | abc.5004.4
373
+ 5004 | 5 | abc.5004.5
374
+ (5 rows)
375
+
376
+ CREATE VIEW fooview2 AS SELECT b.fooid, max(f.foosubid) AS maxsubid
377
+ FROM barrescan b, foorescan f WHERE f.fooid = b.fooid AND b.fooid IN (
378
+ SELECT fooid FROM foorescan(b.fooid)
379
+ ) GROUP BY b.fooid ORDER BY 1,2;
380
+ SELECT * FROM fooview2 AS fv WHERE fv.maxsubid = 5;
381
+ fooid | maxsubid
382
+ -------+----------
383
+ 5003 | 5
384
+ 5004 | 5
385
+ 5005 | 5
386
+ 5006 | 5
387
+ 5007 | 5
388
+ 5008 | 5
389
+ (6 rows)
390
+
391
+ DROP VIEW vw_foorescan;
392
+ DROP VIEW fooview1;
393
+ DROP VIEW fooview2;
394
+ DROP FUNCTION foorescan(int,int);
395
+ DROP FUNCTION foorescan(int);
396
+ DROP TABLE foorescan;
397
+ DROP TABLE barrescan;
@@ -0,0 +1,399 @@
1
+ SELECT * FROM pg_settings WHERE name LIKE 'enable%';
2
+ name | setting | unit | category | short_desc | extra_desc | context | vartype | source | min_val | max_val | enumvals | boot_val | reset_val | sourcefile | sourceline
3
+ -------------------+---------+------+---------------------------------------------+--------------------------------------------------------+------------+---------+---------+---------+---------+---------+----------+----------+-----------+------------+------------
4
+ enable_bitmapscan | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of bitmap-scan plans. | | user | bool | default | | | | on | on | |
5
+ enable_hashagg | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of hashed aggregation plans. | | user | bool | default | | | | on | on | |
6
+ enable_hashjoin | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of hash join plans. | | user | bool | default | | | | on | on | |
7
+ enable_indexscan | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of index-scan plans. | | user | bool | default | | | | on | on | |
8
+ enable_mergejoin | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of merge join plans. | | user | bool | default | | | | on | on | |
9
+ enable_nestloop | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of nested-loop join plans. | | user | bool | default | | | | on | on | |
10
+ enable_seqscan | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of sequential-scan plans. | | user | bool | default | | | | on | on | |
11
+ enable_sort | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of explicit sort steps. | | user | bool | default | | | | on | on | |
12
+ enable_tidscan | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of TID scan plans. | | user | bool | default | | | | on | on | |
13
+ (9 rows)
14
+
15
+ CREATE TABLE foo2(fooid int, f2 int);
16
+ INSERT INTO foo2 VALUES(1, 11);
17
+ INSERT INTO foo2 VALUES(2, 22);
18
+ INSERT INTO foo2 VALUES(1, 111);
19
+ CREATE FUNCTION foot(int) returns setof foo2 as '
20
+ "SELECT * FROM foo2 WHERE fooid = #{args[0]}"'
21
+ language 'plruby';
22
+ select * from foo2, foot(foo2.fooid) z where foo2.f2 = z.f2;
23
+ ERROR: function expression in FROM cannot refer to other relations of same query level
24
+ LINE 1: select * from foo2, foot(foo2.fooid) z where foo2.f2 = z.f2;
25
+ ^
26
+ select * from foo2 where f2 in (
27
+ select f2 from foot(foo2.fooid) z where z.fooid = foo2.fooid
28
+ ) ORDER BY 1,2;
29
+ fooid | f2
30
+ -------+-----
31
+ 1 | 11
32
+ 1 | 111
33
+ 2 | 22
34
+ (3 rows)
35
+
36
+ select * from foo2 where f2 in (
37
+ select f2 from foot(1) z where z.fooid = foo2.fooid
38
+ ) ORDER BY 1,2;
39
+ fooid | f2
40
+ -------+-----
41
+ 1 | 11
42
+ 1 | 111
43
+ (2 rows)
44
+
45
+ select * from foo2 where f2 in (
46
+ select f2 from foot(foo2.fooid) z where z.fooid = 1
47
+ ) ORDER BY 1,2;
48
+ fooid | f2
49
+ -------+-----
50
+ 1 | 11
51
+ 1 | 111
52
+ (2 rows)
53
+
54
+ select foot.fooid, foot.f2 from foot(sin(pi()/2)::int) ORDER BY 1,2;
55
+ fooid | f2
56
+ -------+-----
57
+ 1 | 11
58
+ 1 | 111
59
+ (2 rows)
60
+
61
+ CREATE TABLE foo (fooid int, foosubid int, fooname text, primary key(fooid,foosubid));
62
+ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo"
63
+ INSERT INTO foo VALUES(1,1,'Joe');
64
+ INSERT INTO foo VALUES(1,2,'Ed');
65
+ INSERT INTO foo VALUES(2,1,'Mary');
66
+ CREATE FUNCTION getfoo(int) RETURNS int AS '
67
+ args[0]
68
+ ' language 'plruby';
69
+ SELECT * FROM getfoo(1) AS t1;
70
+ t1
71
+ ----
72
+ 1
73
+ (1 row)
74
+
75
+ CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
76
+ SELECT * FROM vw_getfoo;
77
+ getfoo
78
+ --------
79
+ 1
80
+ (1 row)
81
+
82
+ DROP VIEW vw_getfoo;
83
+ DROP FUNCTION getfoo(int);
84
+ CREATE FUNCTION getfoo(int) RETURNS setof int AS '
85
+ "SELECT fooid FROM foo WHERE fooid = #{args[0]}"
86
+ ' language 'plruby';
87
+ SELECT * FROM getfoo(1) AS t1;
88
+ t1
89
+ ----
90
+ 1
91
+ 1
92
+ (2 rows)
93
+
94
+ CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
95
+ SELECT * FROM vw_getfoo;
96
+ getfoo
97
+ --------
98
+ 1
99
+ 1
100
+ (2 rows)
101
+
102
+ DROP VIEW vw_getfoo;
103
+ DROP FUNCTION getfoo(int);
104
+ CREATE FUNCTION getfoo(int) RETURNS setof text AS '
105
+ "SELECT fooname FROM foo WHERE fooid = #{args[0]}"
106
+ ' language 'plruby';
107
+ SELECT * FROM getfoo(1) AS t1;
108
+ t1
109
+ -----
110
+ Joe
111
+ Ed
112
+ (2 rows)
113
+
114
+ CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
115
+ SELECT * FROM vw_getfoo;
116
+ getfoo
117
+ --------
118
+ Joe
119
+ Ed
120
+ (2 rows)
121
+
122
+ DROP VIEW vw_getfoo;
123
+ DROP FUNCTION getfoo(int);
124
+ CREATE FUNCTION getfoo(int) RETURNS setof foo AS '
125
+ "SELECT * FROM foo WHERE fooid = #{args[0]}"
126
+ ' language 'plruby';
127
+ SELECT * FROM getfoo(1) AS t1;
128
+ fooid | foosubid | fooname
129
+ -------+----------+---------
130
+ 1 | 1 | Joe
131
+ 1 | 2 | Ed
132
+ (2 rows)
133
+
134
+ CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
135
+ SELECT * FROM vw_getfoo;
136
+ fooid | foosubid | fooname
137
+ -------+----------+---------
138
+ 1 | 1 | Joe
139
+ 1 | 2 | Ed
140
+ (2 rows)
141
+
142
+ DROP VIEW vw_getfoo;
143
+ DROP FUNCTION getfoo(int);
144
+ CREATE FUNCTION getfoo(int) RETURNS setof record AS '
145
+ "SELECT * FROM foo WHERE fooid = #{args[0]}"
146
+ ' language 'plruby';
147
+ SELECT * FROM getfoo(1) AS t1(fooid int, foosubid int, fooname text);
148
+ fooid | foosubid | fooname
149
+ -------+----------+---------
150
+ 1 | 1 | Joe
151
+ 1 | 2 | Ed
152
+ (2 rows)
153
+
154
+ CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1) AS (fooid int, foosubid int, fooname text);
155
+ SELECT * FROM vw_getfoo;
156
+ fooid | foosubid | fooname
157
+ -------+----------+---------
158
+ 1 | 1 | Joe
159
+ 1 | 2 | Ed
160
+ (2 rows)
161
+
162
+ DROP VIEW vw_getfoo;
163
+ DROP FUNCTION getfoo(int);
164
+ CREATE FUNCTION getfoo(int) RETURNS setof int AS '
165
+ PL.exec("SELECT fooid FROM foo WHERE fooid = #{args[0]}") do |row|
166
+ yield row.values
167
+ end
168
+ ' language 'plruby';
169
+ SELECT * FROM getfoo(1) AS t1;
170
+ t1
171
+ ----
172
+ 1
173
+ 1
174
+ (2 rows)
175
+
176
+ CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
177
+ SELECT * FROM vw_getfoo;
178
+ getfoo
179
+ --------
180
+ 1
181
+ 1
182
+ (2 rows)
183
+
184
+ DROP VIEW vw_getfoo;
185
+ DROP FUNCTION getfoo(int);
186
+ CREATE FUNCTION getfoo(int) RETURNS setof foo AS '
187
+ PL.exec("SELECT * FROM foo WHERE fooid = #{args[0]}", nil, "value") do |r|
188
+ yield r
189
+ end
190
+ ' language 'plruby';
191
+ SELECT * FROM getfoo(1) AS t1;
192
+ fooid | foosubid | fooname
193
+ -------+----------+---------
194
+ 1 | 1 | Joe
195
+ 1 | 2 | Ed
196
+ (2 rows)
197
+
198
+ CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
199
+ SELECT * FROM vw_getfoo;
200
+ fooid | foosubid | fooname
201
+ -------+----------+---------
202
+ 1 | 1 | Joe
203
+ 1 | 2 | Ed
204
+ (2 rows)
205
+
206
+ DROP VIEW vw_getfoo;
207
+ DROP FUNCTION getfoo(int);
208
+ DROP FUNCTION foot(int);
209
+ DROP TABLE foo2;
210
+ DROP TABLE foo;
211
+ CREATE TABLE foorescan (fooid int, foosubid int, fooname text, primary key(fooid,foosubid));
212
+ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foorescan_pkey" for table "foorescan"
213
+ INSERT INTO foorescan values(5000,1,'abc.5000.1');
214
+ INSERT INTO foorescan values(5001,1,'abc.5001.1');
215
+ INSERT INTO foorescan values(5002,1,'abc.5002.1');
216
+ INSERT INTO foorescan values(5003,1,'abc.5003.1');
217
+ INSERT INTO foorescan values(5004,1,'abc.5004.1');
218
+ INSERT INTO foorescan values(5005,1,'abc.5005.1');
219
+ INSERT INTO foorescan values(5006,1,'abc.5006.1');
220
+ INSERT INTO foorescan values(5007,1,'abc.5007.1');
221
+ INSERT INTO foorescan values(5008,1,'abc.5008.1');
222
+ INSERT INTO foorescan values(5009,1,'abc.5009.1');
223
+ INSERT INTO foorescan values(5000,2,'abc.5000.2');
224
+ INSERT INTO foorescan values(5001,2,'abc.5001.2');
225
+ INSERT INTO foorescan values(5002,2,'abc.5002.2');
226
+ INSERT INTO foorescan values(5003,2,'abc.5003.2');
227
+ INSERT INTO foorescan values(5004,2,'abc.5004.2');
228
+ INSERT INTO foorescan values(5005,2,'abc.5005.2');
229
+ INSERT INTO foorescan values(5006,2,'abc.5006.2');
230
+ INSERT INTO foorescan values(5007,2,'abc.5007.2');
231
+ INSERT INTO foorescan values(5008,2,'abc.5008.2');
232
+ INSERT INTO foorescan values(5009,2,'abc.5009.2');
233
+ INSERT INTO foorescan values(5000,3,'abc.5000.3');
234
+ INSERT INTO foorescan values(5001,3,'abc.5001.3');
235
+ INSERT INTO foorescan values(5002,3,'abc.5002.3');
236
+ INSERT INTO foorescan values(5003,3,'abc.5003.3');
237
+ INSERT INTO foorescan values(5004,3,'abc.5004.3');
238
+ INSERT INTO foorescan values(5005,3,'abc.5005.3');
239
+ INSERT INTO foorescan values(5006,3,'abc.5006.3');
240
+ INSERT INTO foorescan values(5007,3,'abc.5007.3');
241
+ INSERT INTO foorescan values(5008,3,'abc.5008.3');
242
+ INSERT INTO foorescan values(5009,3,'abc.5009.3');
243
+ INSERT INTO foorescan values(5000,4,'abc.5000.4');
244
+ INSERT INTO foorescan values(5001,4,'abc.5001.4');
245
+ INSERT INTO foorescan values(5002,4,'abc.5002.4');
246
+ INSERT INTO foorescan values(5003,4,'abc.5003.4');
247
+ INSERT INTO foorescan values(5004,4,'abc.5004.4');
248
+ INSERT INTO foorescan values(5005,4,'abc.5005.4');
249
+ INSERT INTO foorescan values(5006,4,'abc.5006.4');
250
+ INSERT INTO foorescan values(5007,4,'abc.5007.4');
251
+ INSERT INTO foorescan values(5008,4,'abc.5008.4');
252
+ INSERT INTO foorescan values(5009,4,'abc.5009.4');
253
+ INSERT INTO foorescan values(5000,5,'abc.5000.5');
254
+ INSERT INTO foorescan values(5001,5,'abc.5001.5');
255
+ INSERT INTO foorescan values(5002,5,'abc.5002.5');
256
+ INSERT INTO foorescan values(5003,5,'abc.5003.5');
257
+ INSERT INTO foorescan values(5004,5,'abc.5004.5');
258
+ INSERT INTO foorescan values(5005,5,'abc.5005.5');
259
+ INSERT INTO foorescan values(5006,5,'abc.5006.5');
260
+ INSERT INTO foorescan values(5007,5,'abc.5007.5');
261
+ INSERT INTO foorescan values(5008,5,'abc.5008.5');
262
+ INSERT INTO foorescan values(5009,5,'abc.5009.5');
263
+ CREATE FUNCTION foorescan(int,int) RETURNS setof foorescan AS '
264
+ "SELECT * FROM foorescan WHERE fooid >= #{args[0]} and fooid < #{args[1]}"
265
+ ' language 'plruby';
266
+ SELECT * FROM foorescan f WHERE f.fooid IN (
267
+ SELECT fooid FROM foorescan(5002,5004)
268
+ ) ORDER BY 1,2;
269
+ fooid | foosubid | fooname
270
+ -------+----------+------------
271
+ 5002 | 1 | abc.5002.1
272
+ 5002 | 2 | abc.5002.2
273
+ 5002 | 3 | abc.5002.3
274
+ 5002 | 4 | abc.5002.4
275
+ 5002 | 5 | abc.5002.5
276
+ 5003 | 1 | abc.5003.1
277
+ 5003 | 2 | abc.5003.2
278
+ 5003 | 3 | abc.5003.3
279
+ 5003 | 4 | abc.5003.4
280
+ 5003 | 5 | abc.5003.5
281
+ (10 rows)
282
+
283
+ CREATE VIEW vw_foorescan AS SELECT * FROM foorescan(5002,5004);
284
+ SELECT * FROM foorescan f WHERE f.fooid IN (
285
+ SELECT fooid FROM vw_foorescan
286
+ ) ORDER BY 1,2;
287
+ fooid | foosubid | fooname
288
+ -------+----------+------------
289
+ 5002 | 1 | abc.5002.1
290
+ 5002 | 2 | abc.5002.2
291
+ 5002 | 3 | abc.5002.3
292
+ 5002 | 4 | abc.5002.4
293
+ 5002 | 5 | abc.5002.5
294
+ 5003 | 1 | abc.5003.1
295
+ 5003 | 2 | abc.5003.2
296
+ 5003 | 3 | abc.5003.3
297
+ 5003 | 4 | abc.5003.4
298
+ 5003 | 5 | abc.5003.5
299
+ (10 rows)
300
+
301
+ CREATE TABLE barrescan (fooid int primary key);
302
+ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "barrescan_pkey" for table "barrescan"
303
+ INSERT INTO barrescan values(5003);
304
+ INSERT INTO barrescan values(5004);
305
+ INSERT INTO barrescan values(5005);
306
+ INSERT INTO barrescan values(5006);
307
+ INSERT INTO barrescan values(5007);
308
+ INSERT INTO barrescan values(5008);
309
+ CREATE FUNCTION foorescan(int) RETURNS setof foorescan AS '
310
+ "SELECT * FROM foorescan WHERE fooid = #{args[0]}"
311
+ ' language 'plruby';
312
+ SELECT f.* FROM barrescan b, foorescan f
313
+ WHERE f.fooid = b.fooid AND b.fooid IN (
314
+ SELECT fooid FROM foorescan(b.fooid)
315
+ ) ORDER BY 1,2;
316
+ fooid | foosubid | fooname
317
+ -------+----------+------------
318
+ 5003 | 1 | abc.5003.1
319
+ 5003 | 2 | abc.5003.2
320
+ 5003 | 3 | abc.5003.3
321
+ 5003 | 4 | abc.5003.4
322
+ 5003 | 5 | abc.5003.5
323
+ 5004 | 1 | abc.5004.1
324
+ 5004 | 2 | abc.5004.2
325
+ 5004 | 3 | abc.5004.3
326
+ 5004 | 4 | abc.5004.4
327
+ 5004 | 5 | abc.5004.5
328
+ 5005 | 1 | abc.5005.1
329
+ 5005 | 2 | abc.5005.2
330
+ 5005 | 3 | abc.5005.3
331
+ 5005 | 4 | abc.5005.4
332
+ 5005 | 5 | abc.5005.5
333
+ 5006 | 1 | abc.5006.1
334
+ 5006 | 2 | abc.5006.2
335
+ 5006 | 3 | abc.5006.3
336
+ 5006 | 4 | abc.5006.4
337
+ 5006 | 5 | abc.5006.5
338
+ 5007 | 1 | abc.5007.1
339
+ 5007 | 2 | abc.5007.2
340
+ 5007 | 3 | abc.5007.3
341
+ 5007 | 4 | abc.5007.4
342
+ 5007 | 5 | abc.5007.5
343
+ 5008 | 1 | abc.5008.1
344
+ 5008 | 2 | abc.5008.2
345
+ 5008 | 3 | abc.5008.3
346
+ 5008 | 4 | abc.5008.4
347
+ 5008 | 5 | abc.5008.5
348
+ (30 rows)
349
+
350
+ SELECT b.fooid, max(f.foosubid) FROM barrescan b, foorescan f
351
+ WHERE f.fooid = b.fooid AND b.fooid IN (
352
+ SELECT fooid FROM foorescan(b.fooid)
353
+ ) GROUP BY b.fooid ORDER BY 1,2;
354
+ fooid | max
355
+ -------+-----
356
+ 5003 | 5
357
+ 5004 | 5
358
+ 5005 | 5
359
+ 5006 | 5
360
+ 5007 | 5
361
+ 5008 | 5
362
+ (6 rows)
363
+
364
+ CREATE VIEW fooview1 AS SELECT f.* FROM barrescan b, foorescan f
365
+ WHERE f.fooid = b.fooid AND b.fooid IN (
366
+ SELECT fooid FROM foorescan(b.fooid)
367
+ ) ORDER BY 1,2;
368
+ SELECT * FROM fooview1 AS fv WHERE fv.fooid = 5004;
369
+ fooid | foosubid | fooname
370
+ -------+----------+------------
371
+ 5004 | 1 | abc.5004.1
372
+ 5004 | 2 | abc.5004.2
373
+ 5004 | 3 | abc.5004.3
374
+ 5004 | 4 | abc.5004.4
375
+ 5004 | 5 | abc.5004.5
376
+ (5 rows)
377
+
378
+ CREATE VIEW fooview2 AS SELECT b.fooid, max(f.foosubid) AS maxsubid
379
+ FROM barrescan b, foorescan f WHERE f.fooid = b.fooid AND b.fooid IN (
380
+ SELECT fooid FROM foorescan(b.fooid)
381
+ ) GROUP BY b.fooid ORDER BY 1,2;
382
+ SELECT * FROM fooview2 AS fv WHERE fv.maxsubid = 5;
383
+ fooid | maxsubid
384
+ -------+----------
385
+ 5003 | 5
386
+ 5004 | 5
387
+ 5005 | 5
388
+ 5006 | 5
389
+ 5007 | 5
390
+ 5008 | 5
391
+ (6 rows)
392
+
393
+ DROP VIEW vw_foorescan;
394
+ DROP VIEW fooview1;
395
+ DROP VIEW fooview2;
396
+ DROP FUNCTION foorescan(int,int);
397
+ DROP FUNCTION foorescan(int);
398
+ DROP TABLE foorescan;
399
+ DROP TABLE barrescan;