Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
4ade4fe4
Commit
4ade4fe4
authored
19 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Fix ltreeparentsel so it actually works ...
parent
0f0a3309
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
contrib/ltree/ltree_op.c
+26
-133
26 additions, 133 deletions
contrib/ltree/ltree_op.c
with
26 additions
and
133 deletions
contrib/ltree/ltree_op.c
+
26
−
133
View file @
4ade4fe4
/*
/*
* op function for ltree
* op function for ltree
* Teodor Sigaev <teodor@stack.net>
* Teodor Sigaev <teodor@stack.net>
* $PostgreSQL: pgsql/contrib/ltree/ltree_op.c,v 1.1
0
2006/04/2
6 22:32:36 momjian
Exp $
* $PostgreSQL: pgsql/contrib/ltree/ltree_op.c,v 1.1
1
2006/04/2
7 18:24:35 tgl
Exp $
*/
*/
#include
"ltree.h"
#include
"ltree.h"
#include
<ctype.h>
#include
<ctype.h>
#include
"access/heapam.h"
#include
"catalog/pg_statistic.h"
#include
"nodes/relation.h"
#include
"utils/lsyscache.h"
#include
"utils/lsyscache.h"
#include
"utils/selfuncs.h"
#include
"utils/selfuncs.h"
#include
"utils/syscache.h"
#include
"utils/syscache.h"
/* compare functions */
/* compare functions */
PG_FUNCTION_INFO_V1
(
ltree_cmp
);
PG_FUNCTION_INFO_V1
(
ltree_cmp
);
PG_FUNCTION_INFO_V1
(
ltree_lt
);
PG_FUNCTION_INFO_V1
(
ltree_lt
);
...
@@ -34,6 +33,8 @@ PG_FUNCTION_INFO_V1(ltree_textadd);
...
@@ -34,6 +33,8 @@ PG_FUNCTION_INFO_V1(ltree_textadd);
PG_FUNCTION_INFO_V1
(
lca
);
PG_FUNCTION_INFO_V1
(
lca
);
PG_FUNCTION_INFO_V1
(
ltree2text
);
PG_FUNCTION_INFO_V1
(
ltree2text
);
PG_FUNCTION_INFO_V1
(
text2ltree
);
PG_FUNCTION_INFO_V1
(
text2ltree
);
PG_FUNCTION_INFO_V1
(
ltreeparentsel
);
Datum
ltree_cmp
(
PG_FUNCTION_ARGS
);
Datum
ltree_cmp
(
PG_FUNCTION_ARGS
);
Datum
ltree_lt
(
PG_FUNCTION_ARGS
);
Datum
ltree_lt
(
PG_FUNCTION_ARGS
);
Datum
ltree_le
(
PG_FUNCTION_ARGS
);
Datum
ltree_le
(
PG_FUNCTION_ARGS
);
...
@@ -576,11 +577,7 @@ ltreeparentsel(PG_FUNCTION_ARGS)
...
@@ -576,11 +577,7 @@ ltreeparentsel(PG_FUNCTION_ARGS)
VariableStatData
vardata
;
VariableStatData
vardata
;
Node
*
other
;
Node
*
other
;
bool
varonleft
;
bool
varonleft
;
Datum
*
values
;
double
selec
;
int
nvalues
;
float4
*
numbers
;
int
nnumbers
;
double
selec
=
0
.
0
;
/*
/*
* If expression is not variable <@ something or something <@ variable,
* If expression is not variable <@ something or something <@ variable,
...
@@ -601,131 +598,27 @@ ltreeparentsel(PG_FUNCTION_ARGS)
...
@@ -601,131 +598,27 @@ ltreeparentsel(PG_FUNCTION_ARGS)
PG_RETURN_FLOAT8
(
0
.
0
);
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
))
if
(
IsA
(
other
,
Const
))
{
{
/* Variable is being compared to a known non-null constant */
/* Variable is being compared to a known non-null constant */
Datum
constval
=
((
Const
*
)
other
)
->
constvalue
;
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
;
FmgrInfo
contproc
;
double
mcvsum
;
double
mcvsel
;
fmgr_info
(
get_opcode
(
operator
),
&
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
* Is the constant "<@" to any of the column's most common values?
* 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
);
mcvsel
=
mcv_selectivity
(
&
vardata
,
&
contproc
,
constval
,
varonleft
,
&
mcvsum
);
/*
/*
*
don't return 0.0 selectivity unless all table values are inside
*
We have the exact selectivity for values appearing in the MCV list;
*
mcv
*
use the default selectivity for the rest of the population.
*/
*/
if
(
selec
==
0
.
0
&&
mcvsum
!=
1
.
0
)
selec
=
mcvsel
+
DEFAULT_PARENT_SEL
*
(
1
.
0
-
mcvsum
);
selec
=
DEFAULT_PARENT_SEL
;
}
else
selec
=
DEFAULT_PARENT_SEL
;
}
}
else
else
selec
=
DEFAULT_PARENT_SEL
;
selec
=
DEFAULT_PARENT_SEL
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment