Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
Why would a SQL query take significantly longer to run when the row return limit is increased by 1?

When running the following query:

SELECT customers.ID, customers.FNAME, customers.MNAME, customers.LNAME,
    customers.SUFFIX, addresses.ADDRESS, addresses.CITY, addresses.STATE, 
    addresses.ZIP 
from db_name.customers 
INNER JOIN db_name.addresses ON customers.ID=addresses.CID
limit 6607;

while connected to a MariaDB instance on AWS RDS from MySQL workbench, the query runs with the following metadata results:

6607 row(s) returned Duration: 0.507 sec / Fetch Time: 8.524 sec

Additionally, when the results are exported to a csv file, the size is about 466KB. However, when I run the same query with only changing the last line to retrieve one more row: limit 6608 The query does not finish (I killed it after nearly an hour).

Furthermore, I noticed that the Fetch Time experiences a big jump between limit 4000 and limit 4001 rows. Whether this insight useful or not, I have included a graph of fetch times (fetch time on the vertical axis) while varying the row limit (number of rows returned on the horizontal axis). I do not understand why fetch time appears to be a piecewise continuous (linear) function of rows returned:

Fetch time by row limit scatter plot enter image description here

If anyone has an idea about what is preventing me from returning more than 6607 rows, I would love your advice. Thank you!

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!