PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ gserialized_gist_joinsel()

Datum gserialized_gist_joinsel ( PG_FUNCTION_ARGS  )

Definition at line 1236 of file gserialized_estimate.c.

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

Referenced by gserialized_gist_joinsel_2d(), and gserialized_gist_joinsel_nd().

1237 {
1238  PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
1239  /* Oid operator = PG_GETARG_OID(1); */
1240  List *args = (List *) PG_GETARG_POINTER(2);
1241  JoinType jointype = (JoinType) PG_GETARG_INT16(3);
1242  int mode = PG_GETARG_INT32(4);
1243 
1244  Node *arg1, *arg2;
1245  Var *var1, *var2;
1246  Oid relid1, relid2;
1247 
1248  ND_STATS *stats1, *stats2;
1249  float8 selectivity;
1250 
1251  /* Only respond to an inner join/unknown context join */
1252  if (jointype != JOIN_INNER)
1253  {
1254  elog(DEBUG1, "%s: jointype %d not supported", __func__, jointype);
1255  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1256  }
1257 
1258  /* Find Oids of the geometry columns we are working with */
1259  arg1 = (Node*) linitial(args);
1260  arg2 = (Node*) lsecond(args);
1261  var1 = (Var*) arg1;
1262  var2 = (Var*) arg2;
1263 
1264  /* We only do column joins right now, no functional joins */
1265  /* TODO: handle g1 && ST_Expand(g2) */
1266  if (!IsA(arg1, Var) || !IsA(arg2, Var))
1267  {
1268  elog(DEBUG1, "%s called with arguments that are not column references", __func__);
1269  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1270  }
1271 
1272  /* What are the Oids of our tables/relations? */
1273  relid1 = rt_fetch(var1->varno, root->parse->rtable)->relid;
1274  relid2 = rt_fetch(var2->varno, root->parse->rtable)->relid;
1275 
1276  POSTGIS_DEBUGF(3, "using relations \"%s\" Oid(%d), \"%s\" Oid(%d)",
1277  get_rel_name(relid1) ? get_rel_name(relid1) : "NULL", relid1, get_rel_name(relid2) ? get_rel_name(relid2) : "NULL", relid2);
1278 
1279  /* Pull the stats from the stats system. */
1280  stats1 = pg_get_nd_stats(relid1, var1->varattno, mode, FALSE);
1281  stats2 = pg_get_nd_stats(relid2, var2->varattno, mode, FALSE);
1282 
1283  /* If we can't get stats, we have to stop here! */
1284  if ( ! stats1 )
1285  {
1286  POSTGIS_DEBUGF(3, "unable to retrieve stats for \"%s\" Oid(%d)", get_rel_name(relid1) ? get_rel_name(relid1) : "NULL" , relid1);
1287  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1288  }
1289  else if ( ! stats2 )
1290  {
1291  POSTGIS_DEBUGF(3, "unable to retrieve stats for \"%s\" Oid(%d)", get_rel_name(relid2) ? get_rel_name(relid2) : "NULL", relid2);
1292  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1293  }
1294 
1295  selectivity = estimate_join_selectivity(stats1, stats2);
1296  POSTGIS_DEBUGF(2, "got selectivity %g", selectivity);
1297 
1298  pfree(stats1);
1299  pfree(stats2);
1300  PG_RETURN_FLOAT8(selectivity);
1301 }
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...
#define FALSE
Definition: dbfopen.c:168
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: