Skip to content
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

Bug: 'Unsupported value' in no-index WHERE condition, causes INDEX to not be used #4048

Open
2 tasks done
ioannist opened this issue May 15, 2024 · 1 comment
Open
2 tasks done
Labels
bug Something isn't working triage This issue is new

Comments

@ioannist
Copy link

ioannist commented May 15, 2024

Describe the bug

REMOVE TABLE haircut;

UPDATE haircut:1 CONTENT {
    year: 2022,
    shampoo: "green"
};
UPDATE haircut:1 CONTENT {
    year: 2022,
};


DEFINE INDEX timeIndex ON TABLE haircut COLUMNS year;

SELECT * FROM haircut WHERE year = 2022 EXPLAIN; // uses index as expected
SELECT * FROM haircut WHERE year = 2022 AND shampoo = "green" EXPLAIN; // uses index as expected
SELECT * FROM haircut WHERE year = 2022 AND shampoo IS NONE EXPLAIN; // does NOT use index
SELECT * FROM haircut WHERE year = 2022 AND object::len(shampoo) = 0 EXPLAIN; // does NOT use index

Steps to reproduce

Execute the code above. You will get the following:

-------- Query 1 (583.195µs) --------

NONE

-------- Query 2 (508.196µs) --------

[
	{
		id: haricut:1,
		shampoo: 'green',
		year: 2022
	}
]

-------- Query 3 (404.227µs) --------

[
	{
		id: haricut:1,
		year: 2022
	}
]

-------- Query 4 (619.945µs) --------

NONE

-------- Query 5 (237.478µs) --------

[
	{
		detail: {
			plan: {
				index: 'timeIndex',
				operator: '=',
				value: 2022
			},
			table: 'haircut'
		},
		operation: 'Iterate Index'
	},
	{
		detail: {
			type: 'TempFiles'
		},
		operation: 'Collector'
	}
]

-------- Query 6 (202.879µs) --------

[
	{
		detail: {
			plan: {
				index: 'timeIndex',
				operator: '=',
				value: 2022
			},
			table: 'haircut'
		},
		operation: 'Iterate Index'
	},
	{
		detail: {
			type: 'TempFiles'
		},
		operation: 'Collector'
	}
]

-------- Query 7 (197.169µs) --------

[
	{
		detail: {
			table: 'haircut'
		},
		operation: 'Iterate Table'
	},
	{
		detail: {
			reason: 'Unsupported value: NONE'
		},
		operation: 'Fallback'
	},
	{
		detail: {
			type: 'TempFiles'
		},
		operation: 'Collector'
	}
]

-------- Query 8 (183.269µs) --------

[
	{
		detail: {
			table: 'faircut'
		},
		operation: 'Iterate Table'
	},
	{
		detail: {
			reason: 'Unsupported value: object::len(shampoo)'
		},
		operation: 'Fallback'
	},
	{
		detail: {
			type: 'TempFiles'
		},
		operation: 'Collector'
	}
]

Expected behaviour

The last two SELECTs should use the index too.

SurrealDB version

1.5

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ioannist ioannist added bug Something isn't working triage This issue is new labels May 15, 2024
@ioannist
Copy link
Author

I suspect that the INDEX qualifications are applied to all the conditions instead of being applied only to the conditions that are relevant to the index.

@ioannist ioannist changed the title Bug: 'Unsupported value' causes INDEX to not be used Bug: 'Unsupported value' in no-index WHERE condition, causes INDEX to not be used May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage This issue is new
Projects
None yet
Development

No branches or pull requests

1 participant