MCPcopy Create free account
hub / github.com/apache/cloudberry / create_join_clause

Function create_join_clause

src/backend/optimizer/path/equivclass.c:1830–1903  ·  view source on GitHub ↗

* create_join_clause * Find or make a RestrictInfo comparing the two given EC members * with the given operator. * * parent_ec is either equal to ec (if the clause is a potentially-redundant * join clause) or NULL (if not). We have to treat this as part of the * match requirements --- it's possible that a clause comparing the same two * EMs is a join clause in one join path and a restr

Source from the content-addressed store, hash-verified

1828 * EMs is a join clause in one join path and a restriction clause in another.
1829 */
1830static RestrictInfo *
1831create_join_clause(PlannerInfo *root,
1832 EquivalenceClass *ec, Oid opno,
1833 EquivalenceMember *leftem,
1834 EquivalenceMember *rightem,
1835 EquivalenceClass *parent_ec)
1836{
1837 RestrictInfo *rinfo;
1838 ListCell *lc;
1839 MemoryContext oldcontext;
1840
1841 /*
1842 * Search to see if we already built a RestrictInfo for this pair of
1843 * EquivalenceMembers. We can use either original source clauses or
1844 * previously-derived clauses. The check on opno is probably redundant,
1845 * but be safe ...
1846 */
1847 foreach(lc, ec->ec_sources)
1848 {
1849 rinfo = (RestrictInfo *) lfirst(lc);
1850 if (rinfo->left_em == leftem &&
1851 rinfo->right_em == rightem &&
1852 rinfo->parent_ec == parent_ec &&
1853 opno == ((OpExpr *) rinfo->clause)->opno)
1854 return rinfo;
1855 }
1856
1857 foreach(lc, ec->ec_derives)
1858 {
1859 rinfo = (RestrictInfo *) lfirst(lc);
1860 if (rinfo->left_em == leftem &&
1861 rinfo->right_em == rightem &&
1862 rinfo->parent_ec == parent_ec &&
1863 opno == ((OpExpr *) rinfo->clause)->opno)
1864 return rinfo;
1865 }
1866
1867 /*
1868 * Not there, so build it, in planner context so we can re-use it. (Not
1869 * important in normal planning, but definitely so in GEQO.)
1870 */
1871 oldcontext = MemoryContextSwitchTo(root->planner_cxt);
1872
1873 rinfo = build_implied_join_equality(root,
1874 opno,
1875 ec->ec_collation,
1876 leftem->em_expr,
1877 rightem->em_expr,
1878 bms_union(leftem->em_relids,
1879 rightem->em_relids),
1880 bms_union(leftem->em_nullable_relids,
1881 rightem->em_nullable_relids),
1882 ec->ec_min_security);
1883
1884 /* Mark the clause as redundant, or not */
1885 rinfo->parent_ec = parent_ec;
1886
1887 /*

Calls 5

MemoryContextSwitchToFunction · 0.85
bms_unionFunction · 0.85
lappendFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected