azure-cosmos-db-emulator-docker
azure-cosmos-db-emulator-docker copied to clipboard
Performing a simple SQL query incorrectly returns all documents.
Performing a simple SQL query incorrectly returns all documents.
Steps to reproduce the behavior:
- Run the command
docker run --detach --publish 8081:8081 --publish 1234:1234 --name LocalCosmos mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview - Visit the data explorer interface at http://localhost:1234/
- Add a new database named
ExampleDb - Add a new container in
ExampleDbnamedCustomers. Use the partition keyfdmNumber - Navigate to
ExampleDb->Customers->Items - Using the
Upload itemfeature, import customers.json - Click
New SQL Queryin the top menu - Execute the following SQL:
SELECT c.id,c.fdmNumber,c.type,c.fullname FROM c WHERE (c.fdmNumber = '12345678' and c.type = 'Customer') or (c.fdmNumber = '55664477' and c.type = 'Customer') - Somewhat bizarrely, all 5 documents will be returned.
I would expect to see two matching documents, the ones with ids "782727de-4093-47be-86c3-65b9a51aaf04" and "f62a8f46-3a10-4789-b1f5-f676090fe8d7" but as shown, all 5 are returned:
- OS: Windows 11
- Docker: 27.5.1, build 9f9e405
- Image buildnumber: 20250122.6
The same query executed against the same data in our test, staging and production instances of CosmosDB in Azure works as expected, returning the two expected matches.
It seems like the issue is with the OR operator when it is combined with other operators. So for example this works:
SELECT * FROM c WHERE c.attr1 = "value1" OR c.attr2 = "value2"
but this one breaks:
SELECT * FROM c WHERE c.attr3 = "value3" AND (c.attr1 = "value1" OR c.attr2 = "value2")
The first one works as expected, but the second one returns all records where c.attr3 = "value3", so it's like the second part of the filter (which contains the OR operator) is completely disregarded.
@conTroll Yes, I found similar results, however, combining AND and OR in any kind of combination leads to incorrect results.
@conTroll Yes, I found similar results, however, combining AND and OR in any kind of combination leads to incorrect results.
Here's an example without OR:
SELECT * FROM c WHERE CONTAINS(c.name, "NOTEXIST") AND c.id IN ("1","2")
It returns both items with id "1" and "2".
Note that in Python SDK it returns the correct result: an empty list.