Closed hafedh-trimeche closed 2 months ago
ORDER BY 'DATETIME DESC'
Are you sure about this part? You are sorting by string literal i.e. constant.
ORDER BY DATETIME DESC (without a quote) doesn't work! 12 Rows
With quote the result is: 200 Rows
What Firebird version?
Firebird-5.0.2.1499-0-00c0049-windows-x64
Can you try the same in ISQL? (I have no idea if the tool you're using are modifying the query to make pagination).
Can you also try a "traditional" (and much more optimized version) of the query in this tool and in ISQL?
select *
from AccessLog
where DATETIME BETWEEN timestamp '2024-09-01 00:00:00.000' AND timestamp '2024-10-11 23:59:58.999'
ORDER BY DATETIME DESC
ROWS 200
I'm using FlameRobin 0.9.11
Preparing statement: select *
from AccessLog
where DATETIME BETWEEN timestamp '2024-09-01 00:00:00.000' AND timestamp '2024-10-11 23:59:58.999')
ORDER BY DATETIME DESC
ROWS 200
Error: *** IBPP::SQLException ***
Context: Statement::Prepare( select *
from AccessLog
where DATETIME BETWEEN timestamp '2024-09-01 00:00:00.000' AND timestamp '2024-10-11 23:59:58.999')
ORDER BY DATETIME DESC
ROWS 200
)
Message: isc_dsql_prepare failed
SQL Message : -104
Invalid token
Engine Code : 335544569
Engine Message :
Dynamic SQL Error
SQL error code = -104
Token unknown - line 3, column 104
)
Total execution time: 0.002s
The SQL should be:
select * from AccessLog where DATETIME BETWEEN timestamp '2024-09-01 00:00:00.000' AND timestamp '2024-10-11 23:59:58.999' ORDER BY DATETIME DESC ROWS 200
But gives wrong result!
What' s wrong? Please create complete test case, with data.
Please download this backup: https://mega.nz/file/KxIiyLiJ#j40V-NFbgnuDZJUlrfvggszsGnVoSMF1ILwHN7e0KJ8 SYSDBA / masterkey
I'm not able to reproduce any problem you mentioned with latest v5 source tree.
Sorry, Order By quoted string would caused the problem!
Backup and Restore database solved the problem.
Which would caused the problem?
Maybe some index corruption, which may have happened even due to hardware or disk problem.
Thanks
Please note that this request outputs this result:
select * from AccessLog ORDER BY HEAD_RECORD_AUTOINC DESC ROWS 200
2024-09-11 09:51:39 and 2024-09-11 09:50:12 are included into the result.
but using this Datetime one:
select * from AccessLog where (LOGACTION BETWEEN 0 AND 13) AND (DATETIME BETWEEN CAST('2024-09-10 00:00:00.000' AS TIMESTAMP) AND CAST('2024-09-11 23:59:59.999' AS TIMESTAMP)) ORDER BY DATETIME DESC ROWS 200
the first 7 rows are excluded from the result even DATETIME is inside the range.
This data is not the database you sent. It does not make sense to test things in corrupted database. If you can generate new database or backup that reproduce a problem, reopen this.
Hello, Executing this SQL does not fetch records from the end even the index is descendant.
select * from AccessLog where (CAST(DATETIME AS VARCHAR(24)) BETWEEN '2024-09-01 00:00:00.000' AND '2024-10-11 23:59:58.999') ORDER BY 'DATETIME DESC' ROWS 200
Best regards.