1987{
1988 Oid table_oid1 = PG_GETARG_OID(0);
1989 text *att_text1 = PG_GETARG_TEXT_P(1);
1990 Oid table_oid2 = PG_GETARG_OID(2);
1991 text *att_text2 = PG_GETARG_TEXT_P(3);
1993 float8 selectivity = 0;
1994 int mode = 2;
1995
1996
1997
2000
2001 if ( ! nd_stats1 )
2002 elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid1), text_to_cstring(att_text1));
2003
2004 if ( ! nd_stats2 )
2005 elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid2), text_to_cstring(att_text2));
2006
2007
2008 if ( ! PG_ARGISNULL(4) )
2009 {
2010 text *modetxt = PG_GETARG_TEXT_P(4);
2011 char *modestr = text_to_cstring(modetxt);
2012 if ( modestr[0] == 'N' )
2013 mode = 0;
2014 }
2015
2016
2018
2019 pfree(nd_stats1);
2020 pfree(nd_stats2);
2021 PG_RETURN_FLOAT8(selectivity);
2022}
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?