Skip to content

Performing a simple SQL query incorrectly returns all documents. #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
theplankmeister opened this issue Feb 26, 2025 · 2 comments
Open
Assignees
Labels
cosmosEmulatorVnextPreview issues raised for the vNext Linux based emulator (preview) needs-investigation

Comments

@theplankmeister
Copy link

theplankmeister commented Feb 26, 2025

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 theplankmeister added cosmosEmulatorVnextPreview issues raised for the vNext Linux based emulator (preview) needs-triage labels Feb 26, 2025
@theplankmeister theplankmeister changed the title Performing a simply SQL query incorrectly returns all documents. Performing a simple SQL query incorrectly returns all documents. Feb 26, 2025
@xgerman xgerman assigned lionelc and unassigned xgerman Mar 5, 2025
@conTroll
Copy link

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.

@theplankmeister
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cosmosEmulatorVnextPreview issues raised for the vNext Linux based emulator (preview) needs-investigation
Projects
None yet
Development

No branches or pull requests

4 participants