PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ gserialized_gist_joinsel()

Datum gserialized_gist_joinsel ( PG_FUNCTION_ARGS  )

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

1147 {
1148  PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
1149  /* Oid operator = PG_GETARG_OID(1); */
1150  List *args = (List *) PG_GETARG_POINTER(2);
1151  JoinType jointype = (JoinType) PG_GETARG_INT16(3);
1152  int mode = PG_GETARG_INT32(4);
1153 
1154  Node *arg1, *arg2;
1155  Var *var1, *var2;
1156  Oid relid1, relid2;
1157 
1158  ND_STATS *stats1, *stats2;
1159  float8 selectivity;
1160 
1161  /* Only respond to an inner join/unknown context join */
1162  if (jointype != JOIN_INNER)
1163  {
1164  elog(DEBUG1, "%s: jointype %d not supported", __func__, jointype);
1165  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1166  }
1167 
1168  /* Find Oids of the geometry columns we are working with */
1169  arg1 = (Node*) linitial(args);
1170  arg2 = (Node*) lsecond(args);
1171  var1 = (Var*) arg1;
1172  var2 = (Var*) arg2;
1173 
1174  /* We only do column joins right now, no functional joins */
1175  /* TODO: handle g1 && ST_Expand(g2) */
1176  if (!IsA(arg1, Var) || !IsA(arg2, Var))
1177  {
1178  elog(DEBUG1, "%s called with arguments that are not column references", __func__);
1179  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1180  }
1181 
1182  /* What are the Oids of our tables/relations? */
1183  relid1 = getrelid(var1->varno, root->parse->rtable);
1184  relid2 = getrelid(var2->varno, root->parse->rtable);
1185 
1186  POSTGIS_DEBUGF(3, "using relations \"%s\" Oid(%d), \"%s\" Oid(%d)",
1187  get_rel_name(relid1) ? get_rel_name(relid1) : "NULL", relid1, get_rel_name(relid2) ? get_rel_name(relid2) : "NULL", relid2);
1188 
1189  /* Pull the stats from the stats system. */
1190  stats1 = pg_get_nd_stats(relid1, var1->varattno, mode);
1191  stats2 = pg_get_nd_stats(relid2, var2->varattno, mode);
1192 
1193  /* If we can't get stats, we have to stop here! */
1194  if ( ! stats1 )
1195  {
1196  POSTGIS_DEBUGF(3, "unable to retrieve stats for \"%s\" Oid(%d)", get_rel_name(relid1) ? get_rel_name(relid1) : "NULL" , relid1);
1197  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1198  }
1199  else if ( ! stats2 )
1200  {
1201  POSTGIS_DEBUGF(3, "unable to retrieve stats for \"%s\" Oid(%d)", get_rel_name(relid2) ? get_rel_name(relid2) : "NULL", relid2);
1202  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1203  }
1204 
1205  selectivity = estimate_join_selectivity(stats1, stats2);
1206  POSTGIS_DEBUGF(2, "got selectivity %g", selectivity);
1207 
1208  pfree(stats1);
1209  pfree(stats2);
1210  PG_RETURN_FLOAT8(selectivity);
1211 }
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...
static ND_STATS * pg_get_nd_stats(const Oid table_oid, AttrNumber att_num, int mode)
Pull the stats object from the PgSQL system catalogs.
N-dimensional statistics structure.
Here is the call graph for this function:
Here is the caller graph for this function: