azure-cosmos-db-emulator-docker icon indicating copy to clipboard operation
azure-cosmos-db-emulator-docker copied to clipboard

Performing a simple SQL query incorrectly returns all documents.

Open theplankmeister opened this issue 9 months ago • 2 comments

Performing a simple SQL query incorrectly returns all documents.

Steps to reproduce the behavior:

  1. Run the command docker run --detach --publish 8081:8081 --publish 1234:1234 --name LocalCosmos mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview
  2. Visit the data explorer interface at http://localhost:1234/
  3. Add a new database named ExampleDb
  4. Add a new container in ExampleDb named Customers. Use the partition key fdmNumber
  5. Navigate to ExampleDb -> Customers -> Items
  6. Using the Upload item feature, import customers.json
  7. Click New SQL Query in the top menu
  8. 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')
  9. 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:

Image

  • 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.

theplankmeister avatar Feb 26 '25 09:02 theplankmeister

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 avatar Mar 26 '25 14:03 conTroll

@conTroll Yes, I found similar results, however, combining AND and OR in any kind of combination leads to incorrect results.

theplankmeister avatar Mar 26 '25 21:03 theplankmeister

@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")

Image

It returns both items with id "1" and "2".

Note that in Python SDK it returns the correct result: an empty list.

Image

henrymcl avatar Jun 11 '25 11:06 henrymcl