]> granicus.if.org Git - postgis/commitdiff
Fixed to build cleanly agains pg75
authorSandro Santilli <strk@keybit.net>
Tue, 8 Jun 2004 17:49:14 +0000 (17:49 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 8 Jun 2004 17:49:14 +0000 (17:49 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@612 b70326c6-7e19-0410-871a-916f4a2858ee

postgis_estimate.c

index b6bbd74fb6fd3de1bc648649e8398851c4c8ace6..3c46fd131cc8c40392ba413ffd1719c008cdb234 100644 (file)
@@ -11,6 +11,9 @@
  * 
  **********************************************************************
  * $Log$
+ * Revision 1.22  2004/06/08 17:49:14  strk
+ * Fixed to build cleanly agains pg75
+ *
  * Revision 1.21  2004/04/28 22:26:02  pramsey
  * Fixed spelling mistake in header text.
  *
@@ -962,6 +965,41 @@ postgisgistcostestimate(PG_FUNCTION_ARGS)
 
 #else // USE_VERSION >= 75
 
+
+/*------------ COPIED AND ADAPTED FROM POSTGRESQL --------*/
+
+/*
+ * Locate the n'th cell (counting from 0) of the list.  It is an assertion
+ * error if there isn't one.
+ */
+static ListCell *
+list_nth_cell(List *list, int n)
+{
+        ListCell *match;
+
+        /* Does the caller actually mean to fetch the tail? */
+        if (n == list->length - 1)
+                return list->tail;
+
+        for (match = list->head; n-- > 0; match = match->next)
+                ;
+
+        return match;
+}
+
+/*
+ * Return the data value contained in the n'th element of the
+ * specified list. (List elements begin at 0.)
+ */
+void *
+list_nth(List *list, int n)
+{
+        return lfirst(list_nth_cell(list, n));
+}
+
+/*------------ END COPIED AND ADAPTED FROM POSTGRESQL --------*/
+
+
 /*
  * This function should return an estimation of the number of
  * rows returned by a query involving an overlap check 
@@ -984,7 +1022,7 @@ Datum postgis_gist_sel(PG_FUNCTION_ARGS)
        HeapTuple stats_tuple;
        GEOM_STATS *geomstats;
        int geomstats_nvalues=0;
-       Const *other;
+       Node *other;
        Var *self;
        GEOMETRY *in;
        BOX *search_box;
@@ -994,15 +1032,24 @@ Datum postgis_gist_sel(PG_FUNCTION_ARGS)
        elog(NOTICE, "postgis_gist_sel called");
 #endif
 
+        /* Fail if not a binary opclause (probably shouldn't happen) */
+       if (list_length(args) != 2)
+       {
+#if DEBUG_GEOMETRY_STATS
+               elog(NOTICE, "postgis_gist_sel: not a binary opclause");
+#endif
+               PG_RETURN_FLOAT8(DEFAULT_GEOMETRY_SEL);
+       }
+
+
        /*
         * Find the constant part
         */
-
-       other = (Const *) lfirst(args);
+       other = (Node *) linitial(args);
        if ( ! IsA(other, Const) ) 
        {
                self = (Var *)other;
-               other = (Const *) lsecond(args);
+               other = (Node *) lsecond(args);
        }
        else
        {
@@ -1046,6 +1093,7 @@ Datum postgis_gist_sel(PG_FUNCTION_ARGS)
         */
 
        relid = getrelid(varRelid, root->rtable);
+
        stats_tuple = SearchSysCache(STATRELATT, ObjectIdGetDatum(relid), Int16GetDatum(self->varattno), 0, 0);
        if ( ! stats_tuple )
        {