Skip to content

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
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>
taylorotwell added a commit that referenced this pull request Apr 18, 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 * remove unrelated test --------- 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

2 participants