Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
b3e4aefc
Commit
b3e4aefc
authored
Apr 26, 2006
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhanced containment selectivity function for /contrib/ltree
Matteo Beccati
parent
0df32e3c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
190 additions
and
7 deletions
+190
-7
contrib/ltree/ltree.sql.in
contrib/ltree/ltree.sql.in
+2
-2
src/backend/utils/adt/geo_selfuncs.c
src/backend/utils/adt/geo_selfuncs.c
+2
-2
src/backend/utils/adt/selfuncs.c
src/backend/utils/adt/selfuncs.c
+180
-1
src/include/catalog/pg_proc.h
src/include/catalog/pg_proc.h
+3
-1
src/include/utils/selfuncs.h
src/include/utils/selfuncs.h
+3
-1
No files found.
contrib/ltree/ltree.sql.in
View file @
b3e4aefc
...
@@ -230,7 +230,7 @@ CREATE OPERATOR @> (
...
@@ -230,7 +230,7 @@ CREATE OPERATOR @> (
RIGHTARG = ltree,
RIGHTARG = ltree,
PROCEDURE = ltree_isparent,
PROCEDURE = ltree_isparent,
COMMUTATOR = '<@',
COMMUTATOR = '<@',
RESTRICT =
co
ntsel,
RESTRICT =
pare
ntsel,
JOIN = contjoinsel
JOIN = contjoinsel
);
);
...
@@ -248,7 +248,7 @@ CREATE OPERATOR <@ (
...
@@ -248,7 +248,7 @@ CREATE OPERATOR <@ (
RIGHTARG = ltree,
RIGHTARG = ltree,
PROCEDURE = ltree_risparent,
PROCEDURE = ltree_risparent,
COMMUTATOR = '@>',
COMMUTATOR = '@>',
RESTRICT =
co
ntsel,
RESTRICT =
pare
ntsel,
JOIN = contjoinsel
JOIN = contjoinsel
);
);
...
...
src/backend/utils/adt/geo_selfuncs.c
View file @
b3e4aefc
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/geo_selfuncs.c,v 1.2
7 2006/03/05 15:58:42
momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/geo_selfuncs.c,v 1.2
8 2006/04/26 18:28:29
momjian Exp $
*
*
* XXX These are totally bogus. Perhaps someone will make them do
* XXX These are totally bogus. Perhaps someone will make them do
* something reasonable, someday.
* something reasonable, someday.
...
@@ -20,7 +20,6 @@
...
@@ -20,7 +20,6 @@
#include "utils/geo_decls.h"
#include "utils/geo_decls.h"
/*
/*
* Selectivity functions for geometric operators. These are bogus -- unless
* Selectivity functions for geometric operators. These are bogus -- unless
* we know the actual key distribution in the index, we can't make a good
* we know the actual key distribution in the index, we can't make a good
...
@@ -93,3 +92,4 @@ contjoinsel(PG_FUNCTION_ARGS)
...
@@ -93,3 +92,4 @@ contjoinsel(PG_FUNCTION_ARGS)
{
{
PG_RETURN_FLOAT8
(
0
.
001
);
PG_RETURN_FLOAT8
(
0
.
001
);
}
}
src/backend/utils/adt/selfuncs.c
View file @
b3e4aefc
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.
199 2006/04/20 17:50:18 tgl
Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.
200 2006/04/26 18:28:29 momjian
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -4852,3 +4852,182 @@ gistcostestimate(PG_FUNCTION_ARGS)
...
@@ -4852,3 +4852,182 @@ gistcostestimate(PG_FUNCTION_ARGS)
PG_RETURN_VOID
();
PG_RETURN_VOID
();
}
}
#define DEFAULT_PARENT_SEL 0.001
/*
* parentsel - Selectivity of parent relationship for ltree data types.
*/
Datum
parentsel
(
PG_FUNCTION_ARGS
)
{
PlannerInfo
*
root
=
(
PlannerInfo
*
)
PG_GETARG_POINTER
(
0
);
Oid
operator
=
PG_GETARG_OID
(
1
);
List
*
args
=
(
List
*
)
PG_GETARG_POINTER
(
2
);
int
varRelid
=
PG_GETARG_INT32
(
3
);
VariableStatData
vardata
;
Node
*
other
;
bool
varonleft
;
Datum
*
values
;
int
nvalues
;
float4
*
numbers
;
int
nnumbers
;
double
selec
=
0
.
0
;
/*
* If expression is not variable <@ something or something <@ variable,
* then punt and return a default estimate.
*/
if
(
!
get_restriction_variable
(
root
,
args
,
varRelid
,
&
vardata
,
&
other
,
&
varonleft
))
PG_RETURN_FLOAT8
(
DEFAULT_PARENT_SEL
);
/*
* If the something is a NULL constant, assume operator is strict and
* return zero, ie, operator will never return TRUE.
*/
if
(
IsA
(
other
,
Const
)
&&
((
Const
*
)
other
)
->
constisnull
)
{
ReleaseVariableStats
(
vardata
);
PG_RETURN_FLOAT8
(
0
.
0
);
}
if
(
HeapTupleIsValid
(
vardata
.
statsTuple
))
{
Form_pg_statistic
stats
;
double
mcvsum
=
0
.
0
;
double
mcvsel
=
0
.
0
;
double
hissel
=
0
.
0
;
stats
=
(
Form_pg_statistic
)
GETSTRUCT
(
vardata
.
statsTuple
);
if
(
IsA
(
other
,
Const
))
{
/* Variable is being compared to a known non-null constant */
Datum
constval
=
((
Const
*
)
other
)
->
constvalue
;
bool
match
=
false
;
int
i
;
/*
* Is the constant "<@" to any of the column's most common values?
*/
if
(
get_attstatsslot
(
vardata
.
statsTuple
,
vardata
.
atttype
,
vardata
.
atttypmod
,
STATISTIC_KIND_MCV
,
InvalidOid
,
&
values
,
&
nvalues
,
&
numbers
,
&
nnumbers
))
{
FmgrInfo
contproc
;
fmgr_info
(
get_opcode
(
operator
),
&
contproc
);
for
(
i
=
0
;
i
<
nvalues
;
i
++
)
{
/* be careful to apply operator right way 'round */
if
(
varonleft
)
match
=
DatumGetBool
(
FunctionCall2
(
&
contproc
,
values
[
i
],
constval
));
else
match
=
DatumGetBool
(
FunctionCall2
(
&
contproc
,
constval
,
values
[
i
]));
/* calculate total selectivity of all most-common-values */
mcvsum
+=
numbers
[
i
];
/* calculate selectivity of matching most-common-values */
if
(
match
)
mcvsel
+=
numbers
[
i
];
}
}
else
{
/* no most-common-values info available */
values
=
NULL
;
numbers
=
NULL
;
i
=
nvalues
=
nnumbers
=
0
;
}
free_attstatsslot
(
vardata
.
atttype
,
values
,
nvalues
,
NULL
,
0
);
/*
* Is the constant "<@" to any of the column's histogram values?
*/
if
(
get_attstatsslot
(
vardata
.
statsTuple
,
vardata
.
atttype
,
vardata
.
atttypmod
,
STATISTIC_KIND_HISTOGRAM
,
InvalidOid
,
&
values
,
&
nvalues
,
NULL
,
NULL
))
{
FmgrInfo
contproc
;
fmgr_info
(
get_opcode
(
operator
),
&
contproc
);
for
(
i
=
0
;
i
<
nvalues
;
i
++
)
{
/* be careful to apply operator right way 'round */
if
(
varonleft
)
match
=
DatumGetBool
(
FunctionCall2
(
&
contproc
,
values
[
i
],
constval
));
else
match
=
DatumGetBool
(
FunctionCall2
(
&
contproc
,
constval
,
values
[
i
]));
/* count matching histogram values */
if
(
match
)
hissel
++
;
}
if
(
hissel
>
0
.
0
)
{
/*
* some matching values found inside histogram, divide
* matching entries number by total histogram entries to
* get the histogram related selectivity
*/
hissel
/=
nvalues
;
}
}
else
{
/* no histogram info available */
values
=
NULL
;
i
=
nvalues
=
0
;
}
free_attstatsslot
(
vardata
.
atttype
,
values
,
nvalues
,
NULL
,
0
);
/*
* calculate selectivity based on MCV and histogram result
* histogram selectivity needs to be scaled down if there are any
* most-common-values
*/
selec
=
mcvsel
+
hissel
*
(
1
.
0
-
mcvsum
);
/*
* don't return 0.0 selectivity unless all table values are inside
* mcv
*/
if
(
selec
==
0
.
0
&&
mcvsum
!=
1
.
0
)
selec
=
DEFAULT_PARENT_SEL
;
}
else
selec
=
DEFAULT_PARENT_SEL
;
}
else
selec
=
DEFAULT_PARENT_SEL
;
ReleaseVariableStats
(
vardata
);
/* result should be in range, but make sure... */
CLAMP_PROBABILITY
(
selec
);
PG_RETURN_FLOAT8
((
float8
)
selec
);
}
src/include/catalog/pg_proc.h
View file @
b3e4aefc
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.40
6 2006/04/25 00:25:2
0 momjian Exp $
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.40
7 2006/04/26 18:28:3
0 momjian Exp $
*
*
* NOTES
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
* The script catalog/genbki.sh reads this file and generates .bki
...
@@ -3812,6 +3812,8 @@ DATA(insert OID = 2591 ( gist_circle_consistent PGNSP PGUID 12 f f t f i 3 16 "
...
@@ -3812,6 +3812,8 @@ DATA(insert OID = 2591 ( gist_circle_consistent PGNSP PGUID 12 f f t f i 3 16 "
DESCR
(
"GiST support"
);
DESCR
(
"GiST support"
);
DATA
(
insert
OID
=
2592
(
gist_circle_compress
PGNSP
PGUID
12
f
f
t
f
i
1
2281
"2281"
_null_
_null_
_null_
gist_circle_compress
-
_null_
));
DATA
(
insert
OID
=
2592
(
gist_circle_compress
PGNSP
PGUID
12
f
f
t
f
i
1
2281
"2281"
_null_
_null_
_null_
gist_circle_compress
-
_null_
));
DESCR
(
"GiST support"
);
DESCR
(
"GiST support"
);
DATA
(
insert
OID
=
2599
(
parentsel
PGNSP
PGUID
12
f
f
t
f
s
4
701
"2281 26 2281 23"
_null_
_null_
_null_
parentsel
-
_null_
));
DESCR
(
"enhanced restriction selectivity for ltree isparent comparison operators"
);
/*
/*
...
...
src/include/utils/selfuncs.h
View file @
b3e4aefc
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $PostgreSQL: pgsql/src/include/utils/selfuncs.h,v 1.2
8 2006/03/05 15:59:07
momjian Exp $
* $PostgreSQL: pgsql/src/include/utils/selfuncs.h,v 1.2
9 2006/04/26 18:28:34
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -134,4 +134,6 @@ extern Datum btcostestimate(PG_FUNCTION_ARGS);
...
@@ -134,4 +134,6 @@ extern Datum btcostestimate(PG_FUNCTION_ARGS);
extern
Datum
hashcostestimate
(
PG_FUNCTION_ARGS
);
extern
Datum
hashcostestimate
(
PG_FUNCTION_ARGS
);
extern
Datum
gistcostestimate
(
PG_FUNCTION_ARGS
);
extern
Datum
gistcostestimate
(
PG_FUNCTION_ARGS
);
extern
Datum
parentsel
(
PG_FUNCTION_ARGS
);
#endif
/* SELFUNCS_H */
#endif
/* SELFUNCS_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment