PostgreSQL Source Code: src/backend/optimizer/util/restrictinfo.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
22
23
26 bool is_pushed_down,
27 bool has_clone,
28 bool is_clone,
29 bool pseudoconstant,
30 Index security_level,
31 Relids required_relids,
32 Relids incompatible_relids,
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
54 bool is_pushed_down,
55 bool has_clone,
56 bool is_clone,
57 bool pseudoconstant,
58 Index security_level,
59 Relids required_relids,
60 Relids incompatible_relids,
62{
63
64
65
66
69 clause,
70 is_pushed_down,
71 has_clone,
72 is_clone,
73 pseudoconstant,
74 security_level,
75 required_relids,
76 incompatible_relids,
77 outer_relids);
78
79
81
83 clause,
84 NULL,
85 is_pushed_down,
86 has_clone,
87 is_clone,
88 pseudoconstant,
89 security_level,
90 required_relids,
91 incompatible_relids,
92 outer_relids);
93}
94
95
96
97
98
99
100
101
104 Expr *clause,
105 Expr *orclause,
106 bool is_pushed_down,
107 bool has_clone,
108 bool is_clone,
109 bool pseudoconstant,
110 Index security_level,
111 Relids required_relids,
112 Relids incompatible_relids,
114{
117
118 restrictinfo->clause = clause;
119 restrictinfo->orclause = orclause;
121 restrictinfo->pseudoconstant = pseudoconstant;
122 restrictinfo->has_clone = has_clone;
123 restrictinfo->is_clone = is_clone;
124 restrictinfo->can_join = false;
128
129
130
131
132
133
134 if (security_level > 0)
136 else
137 restrictinfo->leakproof = false;
138
139
140
141
142
143
145
146
147
148
149
151 {
154
155 restrictinfo->clause_relids = bms_union(restrictinfo->left_relids,
156 restrictinfo->right_relids);
157
158
159
160
161
162
163
164 if ((restrictinfo->left_relids) &&
167 restrictinfo->right_relids))
168 {
169 restrictinfo->can_join = true;
170
171 Assert(!restrictinfo->pseudoconstant);
172 }
173 }
174 else
175 {
176
177 restrictinfo->left_relids = NULL;
178 restrictinfo->right_relids = NULL;
179
181 }
182
183
184 if (required_relids != NULL)
186 else
187 restrictinfo->required_relids = restrictinfo->clause_relids;
188
189
190
191
192
193
194
195
196
197
198 baserels = bms_difference(restrictinfo->clause_relids,
199 root->outer_join_rels);
202
203
204
205
207
208
209
210
211
212
213
214
215 restrictinfo->parent_ec = NULL;
216
217 restrictinfo->eval_cost.startup = -1;
218 restrictinfo->norm_selec = -1;
219 restrictinfo->outer_selec = -1;
220
221 restrictinfo->mergeopfamilies = NIL;
222
223 restrictinfo->left_ec = NULL;
224 restrictinfo->right_ec = NULL;
225 restrictinfo->left_em = NULL;
226 restrictinfo->right_em = NULL;
227 restrictinfo->scansel_cache = NIL;
228
229 restrictinfo->outer_is_left = false;
230
231 restrictinfo->hashjoinoperator = InvalidOid;
232
233 restrictinfo->left_bucketsize = -1;
234 restrictinfo->right_bucketsize = -1;
235 restrictinfo->left_mcvfreq = -1;
236 restrictinfo->right_mcvfreq = -1;
237
238 restrictinfo->left_hasheqoperator = InvalidOid;
239 restrictinfo->right_hasheqoperator = InvalidOid;
240
241 return restrictinfo;
242}
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
263 Expr *clause,
264 bool is_pushed_down,
265 bool has_clone,
266 bool is_clone,
267 bool pseudoconstant,
268 Index security_level,
269 Relids required_relids,
270 Relids incompatible_relids,
272{
274 {
277
282 is_pushed_down,
283 has_clone,
284 is_clone,
285 pseudoconstant,
286 security_level,
287 NULL,
288 incompatible_relids,
289 outer_relids));
291 clause,
293 is_pushed_down,
294 has_clone,
295 is_clone,
296 pseudoconstant,
297 security_level,
298 required_relids,
299 incompatible_relids,
300 outer_relids);
301 }
303 {
306
308 andlist = lappend(andlist,
311 is_pushed_down,
312 has_clone,
313 is_clone,
314 pseudoconstant,
315 security_level,
316 required_relids,
317 incompatible_relids,
318 outer_relids));
320 }
321 else
323 clause,
324 NULL,
325 is_pushed_down,
326 has_clone,
327 is_clone,
328 pseudoconstant,
329 security_level,
330 required_relids,
331 incompatible_relids,
332 outer_relids);
333}
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
351{
355
357
358
360 memcpy(newclause, clause, sizeof(OpExpr));
361
362
363 newclause->opno = comm_op;
367
368
371
372
373
374
375
376
377
379 result->left_relids = rinfo->right_relids;
380 result->right_relids = rinfo->left_relids;
381 Assert(result->orclause == NULL);
382 result->left_ec = rinfo->right_ec;
383 result->right_ec = rinfo->left_ec;
384 result->left_em = rinfo->right_em;
385 result->right_em = rinfo->left_em;
386 result->scansel_cache = NIL;
387 if (rinfo->hashjoinoperator == clause->opno)
388 result->hashjoinoperator = comm_op;
389 else
390 result->hashjoinoperator = InvalidOid;
391 result->left_bucketsize = rinfo->right_bucketsize;
392 result->right_bucketsize = rinfo->left_bucketsize;
393 result->left_mcvfreq = rinfo->right_mcvfreq;
394 result->right_mcvfreq = rinfo->left_mcvfreq;
395 result->left_hasheqoperator = InvalidOid;
396 result->right_hasheqoperator = InvalidOid;
397
398 return result;
399}
400
401
402
403
404
405
406bool
408{
409 if (restrictinfo->orclause != NULL)
410 return true;
411 else
412 return false;
413}
414
415
416
417
418
419
420
421bool
424{
425
426
427
428
430 restrictinfo->leakproof)
431 return true;
432 else
433 return false;
434}
435
436
437
438
439
440
441
442
443static inline bool
445{
447 !((Const *) rinfo->clause)->constisnull &&
449}
450
451
452
453
454
455
456
457
458
461{
464
465 foreach(l, restrictinfo_list)
466 {
468
469 Assert(!rinfo->pseudoconstant);
471
473 }
474 return result;
475}
476
477
478
479
480
481
482
483
486 bool pseudoconstant)
487{
490
491 foreach(l, restrictinfo_list)
492 {
494
495 if (rinfo->pseudoconstant == pseudoconstant &&
498 }
499 return result;
500}
501
502
503
504
505
506
507
508
509
510
511
512void
515 List **joinquals,
516 List **otherquals)
517{
519
520 *joinquals = NIL;
521 *otherquals = NIL;
522
523 foreach(l, restrictinfo_list)
524 {
526
528 {
529 if (!rinfo->pseudoconstant &&
531 *otherquals = lappend(*otherquals, rinfo->clause);
532 }
533 else
534 {
535
536 Assert(!rinfo->pseudoconstant);
539 }
540 }
541}
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574bool
576{
577
579 return false;
580
581
583 return false;
584
585
586
587
588
589
590
591
592
593
594
596 return false;
597
598
600 return false;
601
602
604 return false;
605
606 return true;
607}
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660bool
662 Relids currentrelids,
663 Relids current_and_outer)
664{
665
666 if ((rinfo->clause_relids, current_and_outer))
667 return false;
668
669
670 if ((currentrelids, rinfo->clause_relids))
671 return false;
672
673
675 return false;
676
677 return true;
678}
Bitmapset * bms_difference(const Bitmapset *a, const Bitmapset *b)
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
void bms_free(Bitmapset *a)
int bms_num_members(const Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
bool contain_leaked_vars(Node *clause)
Assert(PointerIsAligned(start, uint64))
List * lappend(List *list, void *datum)
Expr * make_orclause(List *orclauses)
Expr * make_andclause(List *andclauses)
static bool is_andclause(const void *clause)
static bool is_orclause(const void *clause)
static Node * get_rightop(const void *clause)
static bool is_opclause(const void *clause)
static Node * get_leftop(const void *clause)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
#define RINFO_IS_PUSHED_DOWN(rinfo, joinrelids)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define list_make2(x1, x2)
static bool DatumGetBool(Datum X)
bool restriction_is_or_clause(RestrictInfo *restrictinfo)
List * extract_actual_clauses(List *restrictinfo_list, bool pseudoconstant)
void extract_actual_join_clauses(List *restrictinfo_list, Relids joinrelids, List **joinquals, List **otherquals)
bool restriction_is_securely_promotable(RestrictInfo *restrictinfo, RelOptInfo *rel)
RestrictInfo * make_plain_restrictinfo(PlannerInfo *root, Expr *clause, Expr *orclause, bool is_pushed_down, bool has_clone, bool is_clone, bool pseudoconstant, Index security_level, Relids required_relids, Relids incompatible_relids, Relids outer_relids)
List * get_actual_clauses(List *restrictinfo_list)
static Expr * make_sub_restrictinfos(PlannerInfo *root, Expr *clause, bool is_pushed_down, bool has_clone, bool is_clone, bool pseudoconstant, Index security_level, Relids required_relids, Relids incompatible_relids, Relids outer_relids)
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
bool join_clause_is_movable_to(RestrictInfo *rinfo, RelOptInfo *baserel)
RestrictInfo * make_restrictinfo(PlannerInfo *root, Expr *clause, bool is_pushed_down, bool has_clone, bool is_clone, bool pseudoconstant, Index security_level, Relids required_relids, Relids incompatible_relids, Relids outer_relids)
RestrictInfo * commute_restrictinfo(RestrictInfo *rinfo, Oid comm_op)
static bool rinfo_is_constant_true(RestrictInfo *rinfo)
Relids lateral_referencers
Index baserestrict_min_security
Relids incompatible_relids
Relids pull_varnos(PlannerInfo *root, Node *node)