2146{
2147 Oid table_oid1 = PG_GETARG_OID(0);
2148 text *att_text1 = PG_GETARG_TEXT_P(1);
2149 Oid table_oid2 = PG_GETARG_OID(2);
2150 text *att_text2 = PG_GETARG_TEXT_P(3);
2152 float8 selectivity = 0;
2153 int mode = 2;
2154
2155
2156
2159
2160 if ( ! nd_stats1 )
2161 elog(ERROR,
"stats for \"%s.%s\" do not exist", get_rel_name(table_oid1),
text_to_cstring(att_text1));
2162
2163 if ( ! nd_stats2 )
2164 elog(ERROR,
"stats for \"%s.%s\" do not exist", get_rel_name(table_oid2),
text_to_cstring(att_text2));
2165
2166
2167 if ( ! PG_ARGISNULL(4) )
2168 {
2169 text *modetxt = PG_GETARG_TEXT_P(4);
2171 if ( modestr[0] == 'N' )
2172 mode = 0;
2173 }
2174
2175
2177
2178 pfree(nd_stats1);
2179 pfree(nd_stats2);
2180 PG_RETURN_FLOAT8(selectivity);
2181}
static ND_STATS * pg_get_nd_stats_by_name(const Oid table_oid, const text *att_text, int mode, bool only_parent)
Pull the stats object from the PgSQL system catalogs.
static float8 estimate_join_selectivity(const ND_STATS *s1, const ND_STATS *s2)
Given two statistics histograms, what is the selectivity of a join driven by the && or &&& operator?
char * text_to_cstring(const text *textptr)
N-dimensional statistics structure.