PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ gserialized_gist_joinsel()

Datum gserialized_gist_joinsel ( PG_FUNCTION_ARGS  )

Definition at line 1270 of file gserialized_estimate.c.

References ovdump::args, DEFAULT_ND_JOINSEL, estimate_join_selectivity(), and pg_get_nd_stats().

Referenced by gserialized_gist_joinsel_2d(), and gserialized_gist_joinsel_nd().

1271 {
1272  PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
1273  /* Oid operator = PG_GETARG_OID(1); */
1274  List *args = (List *) PG_GETARG_POINTER(2);
1275  JoinType jointype = (JoinType) PG_GETARG_INT16(3);
1276  int mode = PG_GETARG_INT32(4);
1277 
1278  Node *arg1, *arg2;
1279  Var *var1, *var2;
1280  Oid relid1, relid2;
1281 
1282  ND_STATS *stats1, *stats2;
1283  float8 selectivity;
1284 
1285  /* Only respond to an inner join/unknown context join */
1286  if (jointype != JOIN_INNER)
1287  {
1288  elog(DEBUG1, "%s: jointype %d not supported", __func__, jointype);
1289  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1290  }
1291 
1292  /* Find Oids of the geometry columns we are working with */
1293  arg1 = (Node*) linitial(args);
1294  arg2 = (Node*) lsecond(args);
1295  var1 = (Var*) arg1;
1296  var2 = (Var*) arg2;
1297 
1298  /* We only do column joins right now, no functional joins */
1299  /* TODO: handle g1 && ST_Expand(g2) */
1300  if (!IsA(arg1, Var) || !IsA(arg2, Var))
1301  {
1302  elog(DEBUG1, "%s called with arguments that are not column references", __func__);
1303  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1304  }
1305 
1306  /* What are the Oids of our tables/relations? */
1307  relid1 = rt_fetch(var1->varno, root->parse->rtable)->relid;
1308  relid2 = rt_fetch(var2->varno, root->parse->rtable)->relid;
1309 
1310  POSTGIS_DEBUGF(3, "using relations \"%s\" Oid(%d), \"%s\" Oid(%d)",
1311  get_rel_name(relid1) ? get_rel_name(relid1) : "NULL", relid1, get_rel_name(relid2) ? get_rel_name(relid2) : "NULL", relid2);
1312 
1313  /* Pull the stats from the stats system. */
1314  stats1 = pg_get_nd_stats(relid1, var1->varattno, mode, false);
1315  stats2 = pg_get_nd_stats(relid2, var2->varattno, mode, false);
1316 
1317  /* If we can't get stats, we have to stop here! */
1318  if ( ! stats1 )
1319  {
1320  POSTGIS_DEBUGF(3, "unable to retrieve stats for \"%s\" Oid(%d)", get_rel_name(relid1) ? get_rel_name(relid1) : "NULL" , relid1);
1321  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1322  }
1323  else if ( ! stats2 )
1324  {
1325  POSTGIS_DEBUGF(3, "unable to retrieve stats for \"%s\" Oid(%d)", get_rel_name(relid2) ? get_rel_name(relid2) : "NULL", relid2);
1326  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1327  }
1328 
1329  selectivity = estimate_join_selectivity(stats1, stats2);
1330  POSTGIS_DEBUGF(2, "got selectivity %g", selectivity);
1331 
1332  pfree(stats1);
1333  pfree(stats2);
1334  PG_RETURN_FLOAT8(selectivity);
1335 }
args
Definition: ovdump.py:44
#define DEFAULT_ND_JOINSEL
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...
N-dimensional statistics structure.
static ND_STATS * pg_get_nd_stats(const Oid table_oid, AttrNumber att_num, int mode, bool only_parent)
Pull the stats object from the PgSQL system catalogs.
Here is the call graph for this function:
Here is the caller graph for this function: