Make WordPress Core

Opened 4 years ago

Closed 18 months ago

#49479 closed enhancement (invalid)

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

Reported by: lambasoft's profile lambasoft Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.3.2
Component: Database Keywords: close
Focuses: performance Cc:


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 (2)

#1 @ayeshrajans
4 years 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.

#2 @JeffPaul
18 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.