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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
476045a2
Commit
476045a2
authored
Sep 11, 2007
by
Teodor Sigaev
Browse files
Options
Downloads
Patches
Plain Diff
Remove QueryOperand->istrue flag, it was used only in cover ranking
(ts_rank_cd). Use palloc'ed array in ranking instead of flag.
parent
13553cbb
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/backend/utils/adt/tsquery.c
+1
-3
1 addition, 3 deletions
src/backend/utils/adt/tsquery.c
src/backend/utils/adt/tsrank.c
+46
-42
46 additions, 42 deletions
src/backend/utils/adt/tsrank.c
src/include/tsearch/ts_type.h
+2
-3
2 additions, 3 deletions
src/include/tsearch/ts_type.h
with
49 additions
and
48 deletions
src/backend/utils/adt/tsquery.c
+
1
−
3
View file @
476045a2
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.
6
2007/09/1
0
1
2:36
:40 teodor Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.
7
2007/09/1
1
1
6:01
:40 teodor Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -784,8 +784,6 @@ tsquerysend(PG_FUNCTION_ARGS)
case
QI_VAL
:
pq_sendint
(
&
buf
,
item
->
operand
.
weight
,
sizeof
(
uint8
));
pq_sendstring
(
&
buf
,
GETOPERAND
(
query
)
+
item
->
operand
.
distance
);
/* istrue flag is just for temporary use in tsrank.c/Cover,
* so we don't need to transfer that */
break
;
case
QI_OPR
:
pq_sendint
(
&
buf
,
item
->
operator
.
oper
,
sizeof
(
item
->
operator
.
oper
));
...
...
...
...
This diff is collapsed.
Click to expand it.
src/backend/utils/adt/tsrank.c
+
46
−
42
View file @
476045a2
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/tsrank.c,v 1.
5
2007/09/11
08:46:29
teodor Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/tsrank.c,v 1.
6
2007/09/11
16:01:40
teodor Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -476,25 +476,20 @@ compareDocR(const void *va, const void *vb)
return
(
a
->
pos
>
b
->
pos
)
?
1
:
-
1
;
}
static
bool
checkcondition_QueryOperand
(
void
*
checkval
,
QueryOperand
*
val
)
typedef
struct
{
return
(
bool
)
(
val
->
istrue
);
}
TSQuery
query
;
bool
*
operandexist
;
}
QueryRepresentation
;
static
void
reset_istrue_flag
(
TSQuery
query
)
{
QueryItem
*
item
=
GETQUERY
(
query
);
int
i
;
#define QR_GET_OPERAND_EXISTS(q, v) ( (q)->operandexist[ ((QueryItem*)(v)) - GETQUERY((q)->query) ] )
#define QR_SET_OPERAND_EXISTS(q, v) QR_GET_OPERAND_EXISTS(q,v) = true
/* reset istrue flag */
for
(
i
=
0
;
i
<
query
->
size
;
i
++
)
static
bool
checkcondition_QueryOperand
(
void
*
checkval
,
QueryOperand
*
val
)
{
if
(
item
->
type
==
QI_VAL
)
item
->
operand
.
istrue
=
0
;
item
++
;
}
QueryRepresentation
*
qr
=
(
QueryRepresentation
*
)
checkval
;
return
QR_GET_OPERAND_EXISTS
(
qr
,
val
);
}
typedef
struct
...
...
@@ -508,7 +503,7 @@ typedef struct
static
bool
Cover
(
DocRepresentation
*
doc
,
int
len
,
TS
Query
query
,
Extention
*
ext
)
Cover
(
DocRepresentation
*
doc
,
int
len
,
Query
Representation
*
qr
,
Extention
*
ext
)
{
DocRepresentation
*
ptr
;
int
lastpos
=
ext
->
pos
;
...
...
@@ -519,7 +514,7 @@ Cover(DocRepresentation *doc, int len, TSQuery query, Extention *ext)
* (though any decent compiler will optimize away the tail-recursion. */
check_stack_depth
();
reset_istrue_flag
(
query
);
memset
(
qr
->
operandexist
,
0
,
sizeof
(
bool
)
*
qr
->
query
->
size
);
ext
->
p
=
0x7fffffff
;
ext
->
q
=
0
;
...
...
@@ -531,9 +526,9 @@ Cover(DocRepresentation *doc, int len, TSQuery query, Extention *ext)
for
(
i
=
0
;
i
<
ptr
->
nitem
;
i
++
)
{
if
(
ptr
->
item
[
i
]
->
type
==
QI_VAL
)
ptr
->
item
[
i
]
->
operand
.
istrue
=
1
;
QR_SET_OPERAND_EXISTS
(
qr
,
ptr
->
item
[
i
])
;
}
if
(
TS_execute
(
GETQUERY
(
query
),
NULL
,
false
,
checkcondition_QueryOperand
))
if
(
TS_execute
(
GETQUERY
(
qr
->
query
),
(
void
*
)
qr
,
false
,
checkcondition_QueryOperand
))
{
if
(
ptr
->
pos
>
ext
->
q
)
{
...
...
@@ -550,7 +545,7 @@ Cover(DocRepresentation *doc, int len, TSQuery query, Extention *ext)
if
(
!
found
)
return
false
;
reset_istrue_flag
(
query
);
memset
(
qr
->
operandexist
,
0
,
sizeof
(
bool
)
*
qr
->
query
->
size
);
ptr
=
doc
+
lastpos
;
...
...
@@ -559,8 +554,8 @@ Cover(DocRepresentation *doc, int len, TSQuery query, Extention *ext)
{
for
(
i
=
0
;
i
<
ptr
->
nitem
;
i
++
)
if
(
ptr
->
item
[
i
]
->
type
==
QI_VAL
)
ptr
->
item
[
i
]
->
operand
.
istrue
=
1
;
if
(
TS_execute
(
GETQUERY
(
query
),
NULL
,
true
,
checkcondition_QueryOperand
))
QR_SET_OPERAND_EXISTS
(
qr
,
ptr
->
item
[
i
])
;
if
(
TS_execute
(
GETQUERY
(
qr
->
query
),
(
void
*
)
qr
,
true
,
checkcondition_QueryOperand
))
{
if
(
ptr
->
pos
<
ext
->
p
)
{
...
...
@@ -583,28 +578,27 @@ Cover(DocRepresentation *doc, int len, TSQuery query, Extention *ext)
}
ext
->
pos
++
;
return
Cover
(
doc
,
len
,
q
uery
,
ext
);
return
Cover
(
doc
,
len
,
q
r
,
ext
);
}
static
DocRepresentation
*
get_docrep
(
TSVector
txt
,
TS
Query
query
,
int
*
doclen
)
get_docrep
(
TSVector
txt
,
Query
Representation
*
qr
,
int
*
doclen
)
{
QueryItem
*
item
=
GETQUERY
(
query
);
QueryItem
*
item
=
GETQUERY
(
qr
->
query
);
WordEntry
*
entry
;
WordEntryPos
*
post
;
int4
dimt
,
j
,
i
;
int
len
=
query
->
size
*
4
,
int
len
=
qr
->
query
->
size
*
4
,
cur
=
0
;
DocRepresentation
*
doc
;
char
*
operand
;
doc
=
(
DocRepresentation
*
)
palloc
(
sizeof
(
DocRepresentation
)
*
len
);
operand
=
GETOPERAND
(
query
);
reset_istrue_flag
(
query
);
operand
=
GETOPERAND
(
qr
->
query
);
for
(
i
=
0
;
i
<
query
->
size
;
i
++
)
for
(
i
=
0
;
i
<
qr
->
query
->
size
;
i
++
)
{
QueryOperand
*
curoperand
;
...
...
@@ -613,10 +607,10 @@ get_docrep(TSVector txt, TSQuery query, int *doclen)
curoperand
=
&
item
[
i
].
operand
;
if
(
item
[
i
].
operand
.
istrue
)
if
(
QR_GET_OPERAND_EXISTS
(
qr
,
&
item
[
i
])
)
continue
;
entry
=
find_wordentry
(
txt
,
query
,
curoperand
);
entry
=
find_wordentry
(
txt
,
qr
->
query
,
curoperand
);
if
(
!
entry
)
continue
;
...
...
@@ -644,9 +638,9 @@ get_docrep(TSVector txt, TSQuery query, int *doclen)
int
k
;
doc
[
cur
].
nitem
=
0
;
doc
[
cur
].
item
=
(
QueryItem
**
)
palloc
(
sizeof
(
QueryItem
*
)
*
query
->
size
);
doc
[
cur
].
item
=
(
QueryItem
**
)
palloc
(
sizeof
(
QueryItem
*
)
*
qr
->
query
->
size
);
for
(
k
=
0
;
k
<
query
->
size
;
k
++
)
for
(
k
=
0
;
k
<
qr
->
query
->
size
;
k
++
)
{
QueryOperand
*
kptr
=
&
item
[
k
].
operand
;
QueryOperand
*
iptr
=
&
item
[
i
].
operand
;
...
...
@@ -658,7 +652,7 @@ get_docrep(TSVector txt, TSQuery query, int *doclen)
/* if k == i, we've already checked above that it's type == Q_VAL */
doc
[
cur
].
item
[
doc
[
cur
].
nitem
]
=
item
+
k
;
doc
[
cur
].
nitem
++
;
item
[
k
].
operand
.
istrue
=
1
;
QR_SET_OPERAND_EXISTS
(
qr
,
item
+
k
)
;
}
}
}
...
...
@@ -699,6 +693,8 @@ calc_rank_cd(float4 *arrdata, TSVector txt, TSQuery query, int method)
PrevExtPos
=
0
.
0
,
CurExtPos
=
0
.
0
;
int
NExtent
=
0
;
QueryRepresentation
qr
;
for
(
i
=
0
;
i
<
lengthof
(
weights
);
i
++
)
{
...
...
@@ -710,12 +706,18 @@ calc_rank_cd(float4 *arrdata, TSVector txt, TSQuery query, int method)
invws
[
i
]
=
1
.
0
/
invws
[
i
];
}
doc
=
get_docrep
(
txt
,
query
,
&
doclen
);
qr
.
query
=
query
;
qr
.
operandexist
=
(
int
*
)
palloc0
(
sizeof
(
bool
)
*
query
->
size
);
doc
=
get_docrep
(
txt
,
&
qr
,
&
doclen
);
if
(
!
doc
)
{
pfree
(
qr
.
operandexist
);
return
0
.
0
;
}
MemSet
(
&
ext
,
0
,
sizeof
(
Extention
));
while
(
Cover
(
doc
,
doclen
,
query
,
&
ext
))
while
(
Cover
(
doc
,
doclen
,
&
qr
,
&
ext
))
{
double
Cpos
=
0
.
0
;
double
InvSum
=
0
.
0
;
...
...
@@ -771,6 +773,8 @@ calc_rank_cd(float4 *arrdata, TSVector txt, TSQuery query, int method)
pfree
(
doc
);
pfree
(
qr
.
operandexist
);
return
(
float4
)
Wdoc
;
}
...
...
@@ -779,7 +783,7 @@ ts_rankcd_wttf(PG_FUNCTION_ARGS)
{
ArrayType
*
win
=
(
ArrayType
*
)
PG_DETOAST_DATUM
(
PG_GETARG_DATUM
(
0
));
TSVector
txt
=
PG_GETARG_TSVECTOR
(
1
);
TSQuery
query
=
PG_GETARG_TSQUERY
_COPY
(
2
);
/* copy because we modify the istrue-flag */
TSQuery
query
=
PG_GETARG_TSQUERY
(
2
);
int
method
=
PG_GETARG_INT32
(
3
);
float
res
;
...
...
@@ -796,7 +800,7 @@ ts_rankcd_wtt(PG_FUNCTION_ARGS)
{
ArrayType
*
win
=
(
ArrayType
*
)
PG_DETOAST_DATUM
(
PG_GETARG_DATUM
(
0
));
TSVector
txt
=
PG_GETARG_TSVECTOR
(
1
);
TSQuery
query
=
PG_GETARG_TSQUERY
_COPY
(
2
);
/* copy because we modify the istrue-flag */
TSQuery
query
=
PG_GETARG_TSQUERY
(
2
);
float
res
;
res
=
calc_rank_cd
(
getWeights
(
win
),
txt
,
query
,
DEF_NORM_METHOD
);
...
...
@@ -811,7 +815,7 @@ Datum
ts_rankcd_ttf
(
PG_FUNCTION_ARGS
)
{
TSVector
txt
=
PG_GETARG_TSVECTOR
(
0
);
TSQuery
query
=
PG_GETARG_TSQUERY
_COPY
(
1
);
/* copy because we modify the istrue-flag */
TSQuery
query
=
PG_GETARG_TSQUERY
(
1
);
int
method
=
PG_GETARG_INT32
(
2
);
float
res
;
...
...
@@ -826,7 +830,7 @@ Datum
ts_rankcd_tt
(
PG_FUNCTION_ARGS
)
{
TSVector
txt
=
PG_GETARG_TSVECTOR
(
0
);
TSQuery
query
=
PG_GETARG_TSQUERY
_COPY
(
1
);
/* copy because we modify the istrue-flag */
TSQuery
query
=
PG_GETARG_TSQUERY
(
1
);
float
res
;
res
=
calc_rank_cd
(
getWeights
(
NULL
),
txt
,
query
,
DEF_NORM_METHOD
);
...
...
...
...
This diff is collapsed.
Click to expand it.
src/include/tsearch/ts_type.h
+
2
−
3
View file @
476045a2
...
...
@@ -5,7 +5,7 @@
*
* Copyright (c) 1998-2007, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/include/tsearch/ts_type.h,v 1.
5
2007/09/11
08:46:29
teodor Exp $
* $PostgreSQL: pgsql/src/include/tsearch/ts_type.h,v 1.
6
2007/09/11
16:01:40
teodor Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -187,8 +187,7 @@ typedef struct
/* pointer to text value of operand, must correlate with WordEntry */
uint32
istrue:
1
,
/* use for ranking in Cover */
length:
11
,
length:
12
,
distance:
20
;
}
QueryOperand
;
...
...
...
...
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