Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the main implementation logic of the function reconsider_outer_join_clauses in PostgreSQL

Shulou Source: shulou.com Published: 2022-05-31 14:39:47 10月03日 Update

< root->

Simple_rel_array_size; rti++) / / set the tag {RelOptInfo * brel = root- > simple_rel_ array [RTI]; if (brel = = NULL) continue; brel- > has_eclass_joins = has_relevant_eclass_joinclause (root, brel) } / * * generate_base_implied_equalities when EC contains pseudoconstant (s) * / static void generate_base_implied_equalities_const (PlannerInfo * root, EquivalenceClass * ec) {EquivalenceMember * const_em = NULL; ListCell * lc; / * * In the trivial case where we just had one "var = const" clause, push * the original clause back into the main planner machinery. There is * nothing to be gained by doing it differently, and we save the effort to * re-build and re-analyze an equality clause that will be exactly * equivalent to the old one. * / if (list_length (ec- > ec_members) = = 2 & & list_length (ec- > ec_sources) = = 1) {RestrictInfo * restrictinfo = (RestrictInfo *) linitial (ec- > ec_sources); if (bms_membership (restrictinfo- > required_relids)! = BMS_MULTIPLE) {distribute_restrictinfo_to_rels (root, restrictinfo); return } / * Find the constant member to use. We prefer an actual constant to * pseudo-constants (such as Params), because the constraint exclusion * machinery might be able to exclude relations on the basis of generated * "var = const" equalities, but "var = param" won't work for that. * / foreach (lc, ec- > ec_members) / / get constant Member {EquivalenceMember * cur_em = (EquivalenceMember *) lfirst (lc); if (cur_em- > em_is_const) {const_em = cur_em; if (cur_em- > em_expr, Const) break }} Assert (const_em! = NULL); / * Generate a derived equality against each other member * / foreach (lc, ec- > ec_members) {EquivalenceMember * cur_em = (EquivalenceMember *) lfirst (lc); Oid eq_op; Assert (! cur_em- > em_is_child) / * no children yet * / if (cur_em = = const_em) continue; eq_op = select_equality_operator (ec, cur_em- > em_datatype, const_em- > em_datatype) If (! OidIsValid (eq_op)) {/ * failed... * / ec- > ec_broken = true; break } process_implied_equality (root, eq_op, ec- > ec_collation, cur_em- > em_expr, const_em- > em_expr, bms_copy (ec- > ec_relids), bms_union (cur_em- > em_nullable_relids) Const_em- > em_nullable_relids), ec- > ec_min_security, ec- > ec_below_outer_join, cur_em- > em_is_const) / / push condition}} / * * generate_base_implied_equalities when EC contains no pseudoconstants * / static void generate_base_implied_equalities_no_const (PlannerInfo * root, EquivalenceClass * ec) {EquivalenceMember * * prev_ems; ListCell * lc; / * * We scan the EC members once and track the last-seen member for each * base relation. When we see another member of the same base relation, * we generate "prev_mem = cur_mem". This results in the minimum number * of derived clauses, but it's possible that it will fail when a * different ordering would succeed. XXX FIXME: use a UNION-FIND * algorithm similar to the way we build merged ECs. (Use a list-of-lists * foreach rel.) * / prev_ems = (EquivalenceMember * *) palloc0 (root- > simple_rel_array_size * sizeof (EquivalenceMember *)); foreach (lc, ec- > ec_members) {EquivalenceMember * cur_em = (EquivalenceMember *) lfirst (lc); int relid; Assert (! cur_em- > em_is_child) / * no children yet * / if (! bms_get_singleton_member (cur_em- > em_relids, & relid)) continue; Assert (relid

< root->

Tags: Condition path function processing equivalence minimum information expression query cost parameter structure logic attribute constant cost data array statement storage Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Technology macOS Shulou Tech Info Docker