1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
2000-02-17 04:40:02 +01:00
|
|
|
* geo_selfuncs.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* Selectivity routines registered in the operator catalog in the
|
|
|
|
* "oprrest" and "oprjoin" attributes.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2000-05-13 08:04:46 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_selfuncs.c,v 1.15 2000/05/13 06:04:46 tgl Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-02-17 04:40:02 +01:00
|
|
|
* XXX These are totally bogus. Perhaps someone will make them do
|
|
|
|
* something reasonable, someday.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
1996-11-10 04:06:38 +01:00
|
|
|
#include "utils/builtins.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-02-17 04:40:02 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Selectivity functions for rtrees. These are bogus -- unless we know
|
|
|
|
* the actual key distribution in the index, we can't make a good prediction
|
|
|
|
* of the selectivity of these operators.
|
|
|
|
*
|
|
|
|
* Note: the values used here may look unreasonably small. Perhaps they
|
|
|
|
* are. For now, we want to make sure that the optimizer will make use
|
|
|
|
* of an r-tree index if one is available, so the selectivity had better
|
|
|
|
* be fairly small.
|
|
|
|
*
|
|
|
|
* In general, rtrees need to search multiple subtrees in order to guarantee
|
|
|
|
* that all occurrences of the same key have been found. Because of this,
|
|
|
|
* the estimated cost for scanning the index ought to be higher than the
|
2000-04-12 19:17:23 +02:00
|
|
|
* output selectivity would indicate. rtcostestimate(), over in selfuncs.c,
|
2000-02-17 04:40:02 +01:00
|
|
|
* ought to be adjusted accordingly --- but until we can generate somewhat
|
|
|
|
* realistic numbers here, it hardly matters...
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Selectivity for operators that depend on area, such as "overlap".
|
|
|
|
*/
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
float64
|
1997-09-07 07:04:48 +02:00
|
|
|
areasel(Oid opid,
|
|
|
|
Oid relid,
|
|
|
|
AttrNumber attno,
|
2000-02-17 04:40:02 +01:00
|
|
|
Datum value,
|
1997-09-07 07:04:48 +02:00
|
|
|
int32 flag)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
float64 result;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
result = (float64) palloc(sizeof(float64data));
|
2000-05-13 08:04:46 +02:00
|
|
|
*result = 0.02;
|
1998-09-01 05:29:17 +02:00
|
|
|
return result;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
float64
|
|
|
|
areajoinsel(Oid opid,
|
1999-03-28 03:56:12 +02:00
|
|
|
Oid relid1,
|
|
|
|
AttrNumber attno1,
|
|
|
|
Oid relid2,
|
|
|
|
AttrNumber attno2)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
float64 result;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
result = (float64) palloc(sizeof(float64data));
|
2000-05-13 08:04:46 +02:00
|
|
|
*result = 0.02;
|
1998-09-01 05:29:17 +02:00
|
|
|
return result;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-02-17 04:40:02 +01:00
|
|
|
* positionsel
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-02-17 04:40:02 +01:00
|
|
|
* How likely is a box to be strictly left of (right of, above, below)
|
|
|
|
* a given box?
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
float64
|
2000-02-17 04:40:02 +01:00
|
|
|
positionsel(Oid opid,
|
|
|
|
Oid relid,
|
|
|
|
AttrNumber attno,
|
|
|
|
Datum value,
|
|
|
|
int32 flag)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
float64 result;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
result = (float64) palloc(sizeof(float64data));
|
2000-02-17 04:40:02 +01:00
|
|
|
*result = 0.1;
|
1998-09-01 05:29:17 +02:00
|
|
|
return result;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
float64
|
2000-02-17 04:40:02 +01:00
|
|
|
positionjoinsel(Oid opid,
|
|
|
|
Oid relid1,
|
|
|
|
AttrNumber attno1,
|
|
|
|
Oid relid2,
|
|
|
|
AttrNumber attno2)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
float64 result;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
result = (float64) palloc(sizeof(float64data));
|
2000-02-17 04:40:02 +01:00
|
|
|
*result = 0.1;
|
1998-09-01 05:29:17 +02:00
|
|
|
return result;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* contsel -- How likely is a box to contain (be contained by) a given box?
|
2000-02-17 04:40:02 +01:00
|
|
|
*
|
|
|
|
* This is a tighter constraint than "overlap", so produce a smaller
|
|
|
|
* estimate than areasel does.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2000-02-17 04:40:02 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
float64
|
|
|
|
contsel(Oid opid,
|
1997-09-07 07:04:48 +02:00
|
|
|
Oid relid,
|
|
|
|
AttrNumber attno,
|
2000-02-17 04:40:02 +01:00
|
|
|
Datum value,
|
1997-09-07 07:04:48 +02:00
|
|
|
int32 flag)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
float64 result;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
result = (float64) palloc(sizeof(float64data));
|
2000-02-17 04:40:02 +01:00
|
|
|
*result = 0.01;
|
1998-09-01 05:29:17 +02:00
|
|
|
return result;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
float64
|
|
|
|
contjoinsel(Oid opid,
|
1999-03-28 03:56:12 +02:00
|
|
|
Oid relid1,
|
|
|
|
AttrNumber attno1,
|
|
|
|
Oid relid2,
|
|
|
|
AttrNumber attno2)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
float64 result;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
result = (float64) palloc(sizeof(float64data));
|
2000-02-17 04:40:02 +01:00
|
|
|
*result = 0.01;
|
1998-09-01 05:29:17 +02:00
|
|
|
return result;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|