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

Skip adding where clauses when search is empty on DatabaseEngine #581

Closed
rodrigopedra opened this issue Feb 8, 2022 · 2 comments
Closed

Comments

@rodrigopedra
Copy link
Contributor

rodrigopedra commented Feb 8, 2022

Right now if we search for an empty string, for example in a endpoint that lists all users:

Route::get('/api/users', fn () => User::search(request()->query('q'))->paginate());

Even when the search string is empty, the where clauses are added:

select *
from `users`
where (`users`.`name` like '%%' or `users`.`email` like '%%' or match (`users`.`notes`) against ('' in natural language mode))
order by `id` desc
limit 30 offset 0

Which for the database driver is irrelevant and could lead the query optimizer to pickup a wrong index (when more constraints are added).

If skipping adding the where clauses when the search string is empty is a desirable I can send a PR.

@driesvints
Copy link
Member

Yeah I think so. Feel free to PR 👍

@rodrigopedra
Copy link
Contributor Author

Thanks @driesvints , sent PR #582

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants