Make WordPress Core

Opened 7 years ago

Closed 4 years ago

#49479 closed enhancement (invalid)

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

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

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

#1 @ayeshrajans
7 years ago

  • Keywords close added
  • Severity majornormal

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
4 years ago

  • Milestone Awaiting Review
  • Resolutioninvalid
  • Status newclosed
Note: See TracTickets for help on using tickets.