Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2026-04-30 9f2ef60949ced4fab4d077a7e1c6d913f3620c9b
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
-- directory paths and dlsuffix are passed to us in environment variables
\getenv abs_srcdir PG_ABS_SRCDIR
\set filename :abs_srcdir '/data/data.csv'
LOAD 'pg_hint_plan';
SET search_path TO public;
SET pg_hint_plan.debug_print TO on;
SET client_min_messages TO LOG;
SET pg_hint_plan.enable_hint TO on;
CREATE EXTENSION file_fdw;
CREATE SERVER file_server FOREIGN DATA WRAPPER file_fdw;
CREATE USER MAPPING FOR PUBLIC SERVER file_server;
CREATE FOREIGN TABLE ft1 (id int, val int) SERVER file_server OPTIONS (format 'csv', filename :'filename');
-- foreign table test
SELECT * FROM ft1;
 id | val 
----+-----
  1 |   1
  2 |   2
  3 |   3
  4 |   4
  5 |   5
  6 |   6
  7 |   7
  8 |   8
  9 |   9
 10 |  10
(10 rows)
 
\t
SELECT explain_filter('
EXPLAIN (COSTS false) SELECT * FROM s1.t1, ft1 ft_1, ft1 ft_2 WHERE t1.c1 = ft_1.id AND t1.c1 = ft_2.id;
');
 Nested Loop
   Join Filter: (t1.c1 = ft_1.id)
   ->  Nested Loop
         Join Filter: (ft_1.id = ft_2.id)
         ->  Foreign Scan on ft1 ft_1
               Foreign File:  (snip..)
         ->  Foreign Scan on ft1 ft_2
               Foreign File:  (snip..)
   ->  Index Scan using t1_i1 on t1
         Index Cond: (c1 = ft_2.id)
 
----
---- No. S-1-5 object type for the hint
----
-- No. S-1-5-6
SELECT explain_filter('
/*+SeqScan(t1)SeqScan(ft_1)SeqScan(ft_2)*/
EXPLAIN (COSTS false) SELECT * FROM s1.t1, ft1 ft_1, ft1 ft_2 WHERE t1.c1 = ft_1.id AND t1.c1 = ft_2.id;
');
LOG:  pg_hint_plan:
used hint:
SeqScan(t1)
not used hint:
SeqScan(ft_1)
SeqScan(ft_2)
duplication hint:
error hint:
 
 Nested Loop
   Join Filter: (t1.c1 = ft_2.id)
   ->  Hash Join
         Hash Cond: (t1.c1 = ft_1.id)
         ->  Seq Scan on t1
         ->  Hash
               ->  Foreign Scan on ft1 ft_1
                     Foreign File:  (snip..)
   ->  Foreign Scan on ft1 ft_2
         Foreign File:  (snip..)
 
----
---- No. J-1-6 object type for the hint
----
-- No. J-1-6-6
SELECT explain_filter('
/*+MergeJoin(ft_1 ft_2)Leading(ft_1 ft_2 t1)*/
EXPLAIN (COSTS false) SELECT * FROM s1.t1, ft1 ft_1, ft1 ft_2 WHERE t1.c1 = ft_1.id AND t1.c1 = ft_2.id;
');
LOG:  pg_hint_plan:
used hint:
MergeJoin(ft_1 ft_2)
Leading(ft_1 ft_2 t1)
not used hint:
duplication hint:
error hint:
 
 Nested Loop
   Join Filter: (t1.c1 = ft_1.id)
   ->  Merge Join
         Merge Cond: (ft_1.id = ft_2.id)
         ->  Sort
               Sort Key: ft_1.id
               ->  Foreign Scan on ft1 ft_1
                     Foreign File:  (snip..)
         ->  Sort
               Sort Key: ft_2.id
               ->  Foreign Scan on ft1 ft_2
                     Foreign File:  (snip..)
   ->  Index Scan using t1_i1 on t1
         Index Cond: (c1 = ft_2.id)
 
----
---- No. L-1-6 object type for the hint
----
-- No. L-1-6-6
SELECT explain_filter('
/*+Leading(ft_1 ft_2 t1)*/
EXPLAIN (COSTS false) SELECT * FROM s1.t1, ft1 ft_1, ft1 ft_2 WHERE t1.c1 = ft_1.id AND t1.c1 = ft_2.id;
');
LOG:  pg_hint_plan:
used hint:
Leading(ft_1 ft_2 t1)
not used hint:
duplication hint:
error hint:
 
 Nested Loop
   Join Filter: (t1.c1 = ft_1.id)
   ->  Nested Loop
         Join Filter: (ft_1.id = ft_2.id)
         ->  Foreign Scan on ft1 ft_1
               Foreign File:  (snip..)
         ->  Foreign Scan on ft1 ft_2
               Foreign File:  (snip..)
   ->  Index Scan using t1_i1 on t1
         Index Cond: (c1 = ft_2.id)
 
----
---- No. R-1-6 object type for the hint
----
-- No. R-1-6-6
SELECT explain_filter('
/*+Rows(ft_1 ft_2 #1)Leading(ft_1 ft_2 t1)*/
EXPLAIN SELECT * FROM s1.t1, ft1 ft_1, ft1 ft_2 WHERE t1.c1 = ft_1.id AND t1.c1 = ft_2.id;
');
LOG:  pg_hint_plan:
used hint:
Leading(ft_1 ft_2 t1)
Rows(ft_1 ft_2 #1)
not used hint:
duplication hint:
error hint:
 
 Nested Loop  (cost=xxx..xxx rows=1 width=xxx)
   Join Filter: (t1.c1 = ft_1.id)
   ->  Nested Loop  (cost=xxx..xxx rows=1 width=xxx)
         Join Filter: (ft_1.id = ft_2.id)
         ->  Foreign Scan on ft1 ft_1  (cost=xxx..xxx rows=1 width=xxx)
               Foreign File:  (snip..)
               Foreign File Size: 42 b
         ->  Foreign Scan on ft1 ft_2  (cost=xxx..xxx rows=1 width=xxx)
               Foreign File:  (snip..)
               Foreign File Size: 42 b
   ->  Index Scan using t1_i1 on t1  (cost=xxx..xxx rows=1 width=xxx)
         Index Cond: (c1 = ft_2.id)