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

[11.x] Optimize pluck() to avoid redundant column selection #54396

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

zsocakave
Copy link
Contributor

Currently, using pluck(column, column) on QueryBuilder results in an unnecessary duplicate column selection in the database query.

Example:

User::pluck('name', 'name'); 

Produces:

SELECT name, name FROM users;

This fix ensures pluck() selects the column only once when the key and value are identical, optimizing queries without changing functionality, test has been added to verify the behavior.

@taylorotwell taylorotwell merged commit 4a74d20 into laravel:11.x Jan 29, 2025
40 checks passed
bert-w added a commit to bert-w/framework that referenced this pull request Feb 14, 2025
taylorotwell added a commit that referenced this pull request Feb 17, 2025
* fetchargs

* add fetchArgs() function

* fetchargs

* add fetchArgs() function

* add afterquery callbacks

* fix typo

* flip afterquerycallback

* fix expectations

* add expectations

* add expectations

* add expectations

* add raw expression test

* rename to fetchUsing

* style

* Remove test from PR #54396

* Revert most Query\Builder changes

* remove DB::raw test

* Revert QueryBuilder pluck tests

* Add base tests for $query->fetchUsing()

* style

* formatting

* Update Builder.php

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
taylorotwell added a commit that referenced this pull request Feb 21, 2025
* fetchargs

* add fetchArgs() function

* fetchargs

* add fetchArgs() function

* add afterquery callbacks

* fix typo

* flip afterquerycallback

* fix expectations

* add expectations

* add expectations

* add expectations

* add raw expression test

* rename to fetchUsing

* style

* Remove test from PR #54396

* Revert most Query\Builder changes

* remove DB::raw test

* Revert QueryBuilder pluck tests

* Add base tests for $query->fetchUsing()

* style

* formatting

* Update Builder.php

* Fix filled columns before calling pluck

* query db compatibility

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
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

Successfully merging this pull request may close these issues.

2 participants