PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ gserialized_gist_joinsel()

Datum gserialized_gist_joinsel ( PG_FUNCTION_ARGS  )

Definition at line 1212 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().

1213 {
1214  PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
1215  /* Oid operator = PG_GETARG_OID(1); */
1216  List *args = (List *) PG_GETARG_POINTER(2);
1217  JoinType jointype = (JoinType) PG_GETARG_INT16(3);
1218  int mode = PG_GETARG_INT32(4);
1219 
1220  Node *arg1, *arg2;
1221  Var *var1, *var2;
1222  Oid relid1, relid2;
1223 
1224  ND_STATS *stats1, *stats2;
1225  float8 selectivity;
1226 
1227  /* Only respond to an inner join/unknown context join */
1228  if (jointype != JOIN_INNER)
1229  {
1230  elog(DEBUG1, "%s: jointype %d not supported", __func__, jointype);
1231  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1232  }
1233 
1234  /* Find Oids of the geometry columns we are working with */
1235  arg1 = (Node*) linitial(args);
1236  arg2 = (Node*) lsecond(args);
1237  var1 = (Var*) arg1;
1238  var2 = (Var*) arg2;
1239 
1240  /* We only do column joins right now, no functional joins */
1241  /* TODO: handle g1 && ST_Expand(g2) */
1242  if (!IsA(arg1, Var) || !IsA(arg2, Var))
1243  {
1244  elog(DEBUG1, "%s called with arguments that are not column references", __func__);
1245  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1246  }
1247 
1248  /* What are the Oids of our tables/relations? */
1249  relid1 = getrelid(var1->varno, root->parse->rtable);
1250  relid2 = getrelid(var2->varno, root->parse->rtable);
1251 
1252  POSTGIS_DEBUGF(3, "using relations \"%s\" Oid(%d), \"%s\" Oid(%d)",
1253  get_rel_name(relid1) ? get_rel_name(relid1) : "NULL", relid1, get_rel_name(relid2) ? get_rel_name(relid2) : "NULL", relid2);
1254 
1255  /* Pull the stats from the stats system. */
1256  stats1 = pg_get_nd_stats(relid1, var1->varattno, mode, FALSE);
1257  stats2 = pg_get_nd_stats(relid2, var2->varattno, mode, FALSE);
1258 
1259  /* If we can't get stats, we have to stop here! */
1260  if ( ! stats1 )
1261  {
1262  POSTGIS_DEBUGF(3, "unable to retrieve stats for \"%s\" Oid(%d)", get_rel_name(relid1) ? get_rel_name(relid1) : "NULL" , relid1);
1263  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1264  }
1265  else if ( ! stats2 )
1266  {
1267  POSTGIS_DEBUGF(3, "unable to retrieve stats for \"%s\" Oid(%d)", get_rel_name(relid2) ? get_rel_name(relid2) : "NULL", relid2);
1268  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1269  }
1270 
1271  selectivity = estimate_join_selectivity(stats1, stats2);
1272  POSTGIS_DEBUGF(2, "got selectivity %g", selectivity);
1273 
1274  pfree(stats1);
1275  pfree(stats2);
1276  PG_RETURN_FLOAT8(selectivity);
1277 }
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: