#1 2019-02-11 12:59:13

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

TSQLRequest EXC with 'Invalid floating point operation' on FTS5 SELECT

Hi,

we have manually created a FTS5 Fulltext-Index, where the following SQL code will crash, when using TSQLRequest:

SELECT GlobalID, Module, Service, DefaultDisplayText FROM ukiFtsMap JOIN (SELECT RowID, Rank FROM ukiFtsIndex WHERE ukiFtsIndex MATCH 'max') ON ID = RowID ORDER BY Rank LIMIT 15 OFFSET 0

When removing the Rank from the SELECT statement, all will execute just fine, however, the important match ranking is lost:

SELECT GlobalID, Module, Service, DefaultDisplayText FROM ukiFtsMap JOIN (SELECT RowID FROM ukiFtsIndex WHERE ukiFtsIndex MATCH 'max') ON ID = RowID LIMIT 15 OFFSET 0

First time, I try to execute this statement in the SynDB Explorer, I get the following error message:

[Window Title]
 SynDB Explorer 1.18.5030 (compiled with Delphi 10.3 Rio 32 bit) - FTS

[Main Instruction]
Error

[Content]
Invalid floating point operation

[Expanded Information]
Exception class: EInvalidOp


[^] Hide details  [OK]

Subsequent request will fail with following error:

[Window Title]
 SynDB Explorer 1.18.5030 (compiled with Delphi 10.3 Rio 32 bit) - FTS

[Main Instruction]
Error

[Content]
Access violation at address 0084C1CC in module 'SynDBExplorer.exe'. Read of address 00000008

[Expanded Information]
Exception class: EAccessViolation


[^] Hide details  [OK]

Please note, that the same SQL will run fine with other SQLite Browsers, so I believe the problem is with the mORMot implementation. However, debugging did not get me very far. :-(

The problem can be recreated with the latest nightly build.

Kind regards,
Daniel

@Arnaud: I can send you a copy of the DB3 file for checking into this.

Offline

#2 2019-02-11 13:14:55

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

Re: TSQLRequest EXC with 'Invalid floating point operation' on FTS5 SELECT

I have created a simple sample, that will reproduce the problem.

Start SynDB Explorer with a new, empty SQLITE3 DB.

Execute each of the following statement separately, the last on will reproduce the error:

CREATE VIRTUAL TABLE Idx USING fts5(A, tokenize='unicode61');
INSERT INTO Idx (RowID, A) VALUES (1, 'hello world');
INSERT INTO Idx (RowID, A) VALUES (2, 'hello max');
INSERT INTO Idx (RowID, A) VALUES (3, 'hello frank');
SELECT RowID, A FROM Idx WHERE Idx MATCH 'max';
SELECT RowID, A FROM Idx WHERE Idx MATCH 'max' ORDER BY Rank;

Regards,
Daniel

Offline

#3 2019-02-11 16:49:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,671
Website

Re: TSQLRequest EXC with 'Invalid floating point operation' on FTS5 SELECT

Did you try to debug a little bit and seek on which source code line the floating point error happens?

Offline

#4 2019-02-11 18:25:04

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

Re: TSQLRequest EXC with 'Invalid floating point operation' on FTS5 SELECT

Well, as I said, I did not get very far. From

function TSQLDBStatement.FetchAllToJSON(JSON: TStream; Expanded: boolean;
  RewindToFirst: boolean): PtrInt;

...
    while Step(RewindToFirst) do begin

it goes into

function TSQLDBSQLite3Statement.Step(SeekFirst: boolean): boolean;
...
    result := fStatement.Step=SQLITE_ROW;

to

function TSQLRequest.Step: integer;
...
    result := sqlite3_check(RequestDB,sqlite3.step(Request),'Step');

Which seems to be a function within the SQLite driver. (sqlite3.step(Request))

Then it jumps into

function memset(P: Pointer; B: Integer; count: Integer): pointer; cdecl; { always cdecl }
// a fast full pascal version of the standard C library function
begin
  FillCharFast(P^, count, B);
  result := P;
end;

and upon return into the CPU view... :-(

Regards,
Daniel

Last edited by sakura (2019-02-11 18:25:57)

Offline

#5 2019-02-11 19:49:50

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

Re: TSQLRequest EXC with 'Invalid floating point operation' on FTS5 SELECT

At some point, following function gets called (Unit SynSQLite3Static):

function log(const val: extended): extended;
asm
  fld val
  fldln2
  fxch
  fyl2x
  fwait
end;

Upon coming to fwait, the exception is thrown.

Offline

#6 2019-02-12 17:49:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,671
Website

Re: TSQLRequest EXC with 'Invalid floating point operation' on FTS5 SELECT

Could you try to replace the low-level asm code by the following:

function log(const val: extended): extended;
begin
  result := ln(val);
end;

OR
just comment the fwait ?

My guess is that the SQlite3.obj code doesn't use FPU exceptions, so the linked log() value shouldn't be used either...

Offline

#7 2019-02-12 18:14:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,671
Website

Re: TSQLRequest EXC with 'Invalid floating point operation' on FTS5 SELECT

Update: I guess I found the root cause.

On my side after https://synopse.info/fossil/info/fe4a3b9b56 FTS+RANK works fine now.

Offline

#8 2019-02-13 08:05:23

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

Re: TSQLRequest EXC with 'Invalid floating point operation' on FTS5 SELECT

Hello Arnaud,

thx for your service, this fixed it for me too.

Kind regards,
Daniel

Offline

Board footer

Powered by FluxBB