WordPress.org

Make WordPress Core

Opened 6 months ago

Last modified 6 months ago

#49479 new enhancement

Does $wpdb->get_row() add LIMIT 1 to the query?

Reported by: lambasoft Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.3.2
Component: Database Keywords: close
Focuses: performance Cc:

Description

I've been trying to investigate either $wpdb->get_row() adds a LIMIT 1 dynamically to the executed query, since it only returns 1 row. But couldn't find the LIMIT added anywhere in the code.

Does that mean that $wpdb->get_row() does not add LIMIT 1 dynamically to the query? If so, shouldn't it?

Change History (1)

#1 @ayeshrajans
6 months ago

  • Keywords close added
  • Severity changed from major to normal

Hi @lambasoft - Welcome to WordPress Trac.

To answer your question: No, it does not add a .. LIMIT 1 clause to the query. It runs the query, and returns one result and that's it. I suppose adding LIMIT 1 would give a performance benefit, but this get_row is meant to be used on database structures that contains exactly one result or none (for example to load a user by a specific ID). To load multiple results, use wpdb::get_results.

Note: See TracTickets for help on using tickets.