wrong number of arguments to function rank()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

wrong number of arguments to function rank()

Andrea Spacca
Hello,

I experienced seeing no results for search in matrix-syanpse backed by
sqlite3 storage. Tracking down the their source code I identified the
query:
https://github.com/matrix-org/synapse/blob/v1.9.1/synapse/storage/data_stores/main/search.py#L424

I then run the query directly on a copy of the database getting the
error in the subject. I run an integrity check on the fts and no error
was reported.

To be sure I started from a new database, create the virtual table and
inserted data to run the query on. Same result:
sqlite> CREATE VIRTUAL TABLE event_search_test USING fts4 ( event_id,
room_id, sender, key, value );
sqlite> INSERT INTO event_search_test VALUES('test','test','','test','a
matching string');
sqlite> SELECT * FROM event_search_test WHERE value MATCH "string";
test|test||test|a matching string
sqlite> SELECT quote(matchinfo(event_search_test)) as rank, room_id,
event_id, value FROM event_search_test WHERE value MATCH "string";
X'0100000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000100000001000000'|test|test|a
matching string
sqlite> SELECT rank(matchinfo(event_search_test)) as rank, room_id,
event_id, value FROM event_search_test WHERE value MATCH "string";
Error: wrong number of arguments to function rank()



I'm running sqlite3 3.27.2 on a Debian 10 machine.
I looked at
https://github.com/sqlite/sqlite/blob/version-3.27.2/src/test_func.c#L828 
and I can see that the error is somehow related to the mismatching
between the second unsinged 32bit integer in the matchinfo returned blob
and the nVal in the rankfunc param (please, correct me if I'm wrong).

I don't know exactly which nVal value rankfunc receives, I can see that
upon sqlite3_create_function call for the function it takes -1 as
variable number of arguments.

I see that the nCol in my query is 5, so I expect nVal to have something
like the value of the number of column in the fst table plus the hidden
one: in this case the value would match, but this is clearly not the
case in my test.

Similar test failed as well:
sqlite> CREATE VIRTUAL TABLE another_test USING fts4 (a_field,
another_field);
sqlite> INSERT INTO another_test VALUES('test', 'test');
sqlite> SELECT * FROM another_test WHERE a_field MATCH "test";
test|test
sqlite> SELECT quote(matchinfo(another_test)) as rank, a_field FROM
another_test WHERE a_field MATCH "test";
X'0100000002000000010000000100000001000000000000000000000000000000'|test
sqlite> SELECT rank(matchinfo(another_test)) as rank, a_field FROM
another_test WHERE a_field MATCH "test";
Error: wrong number of arguments to function rank()


I cannot find any bug related to this problem, so I guess is somehow
related to my env.

Thanks,
Andrea Spacca


_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: wrong number of arguments to function rank()

Dan Kennedy-4

On 6/2/63 19:00, Andrea Spacca wrote:

> Hello,
>
> I experienced seeing no results for search in matrix-syanpse backed by
> sqlite3 storage. Tracking down the their source code I identified the
> query:
> https://github.com/matrix-org/synapse/blob/v1.9.1/synapse/storage/data_stores/main/search.py#L424
>
> I then run the query directly on a copy of the database getting the
> error in the subject. I run an integrity check on the fts and no error
> was reported.
>
> To be sure I started from a new database, create the virtual table and
> inserted data to run the query on. Same result:
> sqlite> CREATE VIRTUAL TABLE event_search_test USING fts4 ( event_id,
> room_id, sender, key, value );
> sqlite> INSERT INTO event_search_test
> VALUES('test','test','','test','a matching string');
> sqlite> SELECT * FROM event_search_test WHERE value MATCH "string";
> test|test||test|a matching string
> sqlite> SELECT quote(matchinfo(event_search_test)) as rank, room_id,
> event_id, value FROM event_search_test WHERE value MATCH "string";
> X'0100000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000100000001000000'|test|test|a
> matching string
> sqlite> SELECT rank(matchinfo(event_search_test)) as rank, room_id,
> event_id, value FROM event_search_test WHERE value MATCH "string";
> Error: wrong number of arguments to function rank()

Looks like there should be one argument after the "matchinfo" for each
column in the table. So:

   SELECT rank(matchinfo(event_search_test), 1.0, 1.0) AS rank, room_id...

Dan.


>
>
>
> I'm running sqlite3 3.27.2 on a Debian 10 machine.
> I looked at
> https://github.com/sqlite/sqlite/blob/version-3.27.2/src/test_func.c#L828 
> and I can see that the error is somehow related to the mismatching
> between the second unsinged 32bit integer in the matchinfo returned
> blob and the nVal in the rankfunc param (please, correct me if I'm
> wrong).
>
> I don't know exactly which nVal value rankfunc receives, I can see
> that upon sqlite3_create_function call for the function it takes -1 as
> variable number of arguments.
>
> I see that the nCol in my query is 5, so I expect nVal to have
> something like the value of the number of column in the fst table plus
> the hidden one: in this case the value would match, but this is
> clearly not the case in my test.
>
> Similar test failed as well:
> sqlite> CREATE VIRTUAL TABLE another_test USING fts4 (a_field,
> another_field);
> sqlite> INSERT INTO another_test VALUES('test', 'test');
> sqlite> SELECT * FROM another_test WHERE a_field MATCH "test";
> test|test
> sqlite> SELECT quote(matchinfo(another_test)) as rank, a_field FROM
> another_test WHERE a_field MATCH "test";
> X'0100000002000000010000000100000001000000000000000000000000000000'|test
> sqlite> SELECT rank(matchinfo(another_test)) as rank, a_field FROM
> another_test WHERE a_field MATCH "test";
> Error: wrong number of arguments to function rank()
>
>
> I cannot find any bug related to this problem, so I guess is somehow
> related to my env.
>
> Thanks,
> Andrea Spacca
>
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: wrong number of arguments to function rank()

Andrea Spacca
 > Looks like there should be one argument after the "matchinfo" for
each > column in the table. So:

 >  SELECT rank(matchinfo(event_search_test), 1.0, 1.0) AS rank,
 > room_id...

Yes, I realised that nVal is the number of arguments passed to the
function, so  according to nVal!=(1+nCol) I have to pass as many
argument after matchinfo() as the number of columns.

This means that the documention is at least misleading, and also I was
not able to make it work anyway

I'm using the example from the docs:

sqlite> CREATE VIRTUAL TABLE documents USING fts4(title, content);
sqlite> INSERT INTO documents VALUES ('title', 'content');
sqlite> SELECT quote(matchinfo(documents)) FROM documents WHERE title
MATCH 'title';
X'0100000002000000010000000100000001000000000000000000000000000000'
sqlite> SELECT rank(matchinfo(documents), 1.0, 1.0) FROM documents WHERE
title MATCH 'title';
Error: wrong number of arguments to function rank()


_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users