Repository navigation
Description
ArcadeDB Version:
ArcadeDB Server v24.11.1-SNAPSHOT (build 4207821d055e37cbd74b76683e45073da759c2de/1729083296142/console)
OS and JDK Version:
Running on Mac OS X 12.7.6 - OpenJDK 64-Bit Server VM 17.0.12 (Homebrew)
Querying a database can return the wrong number of records, in particular too many records. This problem is not easy to reproduce so I attach a small database (75 records) generated from public data. This behavior occurs when from certain databases, such as the one provided below, is queried via SQL, ie SELECT, where an (not-unique) indexed property is used in the projection and also as ordering quantity (in ORDER BY). The schema is given here: https://github.com/ulbmuenster/dataasee/blob/main/database/schema.sql
Expected behavior
Correct number of records returned.
Actual behavior
Too many records are returned.
Steps to reproduce
Restore this backup: metadatalake-backup-20240829-100753793.zip (337KB)
SELECT count(*) FROM metadata; -- There are 75 records in the database
SELECT name, publicationYear FROM metadata; -- Returns 75 records correctly
SELECT name FROM metadata ORDER BY publicationYear; -- Returns 75 records correctly
SELECT name, publicationYear FROM metadata ORDER BY publicationYear; -- Returns 117 records INCORRECTLY
Notes
End of August (2024-08-28 -- 2024-08-31) @lvca (and I) looked into this and potential sources of this behavior could be:
FetchFromIndexStep- The
UPSERTentering the data.
Here is a sample UPSERT statement that generated the provided database:
UPDATE metadata MERGE {"creators":[{"@type":"pair","name":"Neumann, Georg"},{"@type":"pair","name":"Boivin, Odette"},{"@type":"pair","name":"Kleber, Kristin"},{"@type":"pair","name":"Neumann, Georg"},{"@type":"pair","name":"Boivin, Odette"},{"@type":"pair","name":"Kleber, Kristin"}],"dataLocation":"https://data-management.uni-muenster.de/direct-access/wwurdm/07988641231","dataSteward":"https://datastore.uni-muenster.de","description":"The dataset comprises the RTI-data of the cuneiform tablet VAT 17966 (N5:27).\\n\\nRTI = Reflectance Transformation Imaging (RTI) is a computational photographic method that captures a subject’s surface shape and color and enables the interactive re-lighting of the subject from any direction in a software viewer, revealing details not visible with the naked eye (cf. https://culturalheritageimaging.org/).","identifiers":[{"@type":"pair","data":"10.17879/07988641225","name":"DE-6"},{"@type":"pair","data":"10.17879/07988641225","name":"null"}],"keywords":"Babylon,Cuneiform,Neo-Babylonian","language":"#4:0","metadataQuality":"Incomplete","name":"VAT 17966 - RTI dataset","publicationYear":2024,"publisher":"Universität Münster","rawChecksum":"TcrJlnTQYfugD2rROs2Y3g==","rawType":"marc21","recordId":"MTA0MzQ4NDE4NDMwODAyNDg3NA","resourceType":null,"rights":"CC BY-NC-SA 4.0","source":"https://datastore.uni-muenster.de/oai","synonyms":[{"@type":"pair","data":"GoviB","name":"Alternative Title"}]} UPSERT WHERE recordId == 'MTA0MzQ4NDE4NDMwODAyNDg3NA';
As a workaround the projection can be renamed, ie:
SELECT name, publicationYear AS pubYear FROM metadata ORDER BY publicationYear;
but this also excludes the use of the index!
Activity
[-]Index returns too many entries when used with `ORDER BY`[/-][+]SQL: Index returns too many entries when used with `ORDER BY`[/+][-]SQL: Index returns too many entries when used with `ORDER BY`[/-][+]SQL: Index can return too many entries when used with `ORDER BY`[/+]gramian commentedon Oct 17, 2024
Using either
UPDATE ... MERGE ... UPSERTorUPDATE ... CONTENT ... UPSERTproduces too many index results.gramian commentedon Nov 29, 2024
Here is some more testing which may help locate the source:
ASCandDESCproduce these duplicate results but different numbers: 146 forASC, and 117 forDESCfor a database with 81 records.INSERT INTO ... CONTENT ...DISTINCTremoves the duplicates but this is no workaround as the in paged results the duplicates may be spread.gramian commentedon Dec 11, 2024
More testing reveals:
ORDER BY publicationYear, namereturns the correct amount of results. @lvca This does also not use thepublicationYearindex, right?SHORT,INTEGER, andLONG).gramian commentedon Jan 30, 2025
@robfrank Here is another test case using 25.1.1. It is the smallest I could produce yet with 39 records: metadatalake-backup-20250130-122441030.zip
The query:
SELECT name FROM metadata ORDER BY publicationYearproduces correctly 39 results, while the querySELECT name, publicationYear FROM metadata ORDER BY publicationYearreturns 50 results.(Reminder: these duplicates appear when a projected indexed property is also order key, here
publicationYear)And another observation:
Using
REBUILD INDEX *causes the querySELECT name, publicationYear FROM metadata ORDER BY publicationYearto return 40 results. So the rebuild still produces the duplicate results, yet lesser.I hope this can help.
gramian commentedon Feb 12, 2025
Here is some more info that may help:
commandendpoint using theSQLscriptlanguage.Uniqueindex is running on the propertyrecordIdwhich is of typestringwith the attributes(mandatory true, notnull true, readonly true, max 31)22 remaining items
gramian commentedon Sep 30, 2025
Works! Very Cool. Thank you very much @lvca
fix: index cursor returning same entry multiple times
fix: fixed query with order by that uses the index to browse the resu…
chore(deps): bump jline.version from 4.0.10 to 4.0.12 [skip ci]
chore(deps): bump org.neo4j.driver:neo4j-java-driver from 6.0.5 to 6.…
fix: index cursor returning same entry multiple times
fix: fixed query with order by that uses the index to browse the resu…
chore(deps): bump jline.version from 4.0.10 to 4.0.12 [skip ci]
chore(deps): bump org.neo4j.driver:neo4j-java-driver from 6.0.5 to 6.…
chore(deps): bump actions/cache/restore from 5.0.5 to 6.1.0 [skip ci]
chore(deps): bump actions/cache from 5.0.5 to 6.1.0 [skip ci]
chore(deps): bump actions/cache/save from 5.0.5 to 6.1.0 [skip ci]
chore(deps): bump org.neo4j.driver:neo4j-java-driver from 4.4.20 to 6…
chore(deps): bump actions/cache from 4.3.0 to 6.1.0 [skip ci]