PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ gserialized_gist_joinsel()

Datum gserialized_gist_joinsel ( PG_FUNCTION_ARGS  )

Definition at line 1276 of file gserialized_estimate.c.

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

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().

Here is the call graph for this function:
Here is the caller graph for this function: