PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum gserialized_gist_joinsel ( PG_FUNCTION_ARGS  )

Definition at line 1126 of file gserialized_estimate.c.

References DEFAULT_ND_JOINSEL, estimate_join_selectivity(), and pg_get_nd_stats().

Referenced by gserialized_gist_joinsel_2d(), and gserialized_gist_joinsel_nd().

1127 {
1128  PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
1129  /* Oid operator = PG_GETARG_OID(1); */
1130  List *args = (List *) PG_GETARG_POINTER(2);
1131  JoinType jointype = (JoinType) PG_GETARG_INT16(3);
1132  int mode = PG_GETARG_INT32(4);
1133 
1134  Node *arg1, *arg2;
1135  Var *var1, *var2;
1136  Oid relid1, relid2;
1137 
1138  ND_STATS *stats1, *stats2;
1139  float8 selectivity;
1140 
1141  /* Only respond to an inner join/unknown context join */
1142  if (jointype != JOIN_INNER)
1143  {
1144  elog(NOTICE, "gserialized_gist_joinsel: jointype %d not supported", jointype);
1145  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1146  }
1147 
1148  /* Find Oids of the geometry columns we are working with */
1149  arg1 = (Node*) linitial(args);
1150  arg2 = (Node*) lsecond(args);
1151  var1 = (Var*) arg1;
1152  var2 = (Var*) arg2;
1153 
1154  /* We only do column joins right now, no functional joins */
1155  /* TODO: handle g1 && ST_Expand(g2) */
1156  if (!IsA(arg1, Var) || !IsA(arg2, Var))
1157  {
1158  elog(DEBUG1, "gserialized_gist_joinsel called with arguments that are not column references");
1159  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1160  }
1161 
1162  /* What are the Oids of our tables/relations? */
1163  relid1 = getrelid(var1->varno, root->parse->rtable);
1164  relid2 = getrelid(var2->varno, root->parse->rtable);
1165 
1166  POSTGIS_DEBUGF(3, "using relations \"%s\" Oid(%d), \"%s\" Oid(%d)",
1167  get_rel_name(relid1) ? get_rel_name(relid1) : "NULL", relid1, get_rel_name(relid2) ? get_rel_name(relid2) : "NULL", relid2);
1168 
1169  /* Pull the stats from the stats system. */
1170  stats1 = pg_get_nd_stats(relid1, var1->varattno, mode);
1171  stats2 = pg_get_nd_stats(relid2, var2->varattno, mode);
1172 
1173  /* If we can't get stats, we have to stop here! */
1174  if ( ! stats1 )
1175  {
1176  POSTGIS_DEBUGF(3, "unable to retrieve stats for \"%s\" Oid(%d)", get_rel_name(relid1) ? get_rel_name(relid1) : "NULL" , relid1);
1177  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1178  }
1179  else if ( ! stats2 )
1180  {
1181  POSTGIS_DEBUGF(3, "unable to retrieve stats for \"%s\" Oid(%d)", get_rel_name(relid2) ? get_rel_name(relid2) : "NULL", relid2);
1182  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1183  }
1184 
1185  selectivity = estimate_join_selectivity(stats1, stats2);
1186  POSTGIS_DEBUGF(2, "got selectivity %g", selectivity);
1187 
1188  pfree(stats1);
1189  pfree(stats2);
1190  PG_RETURN_FLOAT8(selectivity);
1191 }
#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: