Solved

Practical Limit on Length of MySQLi Query String

Posted on 2013-10-24
3
964 Views
Last Modified: 2013-10-24
I'm building an export application to run against a table with about 20,000 rows.  Each row needs to be written to the output file, then the row will be marked by changing the "exported" column from default 'N' to 'Y' so that we know which rows have been exported.

The idea of running 20,000 update queries makes me itch, so I was thinking along the lines of using a single query with a clause like WHERE id IN (1,2,3,4,5 ... 20000)

It seems like this query string might be nearly 100,000 characters.  

Is there a practical limit on the length of the query string?  Or any other "gotcha" lurking in this idea?

Is there a "best practice" way of doing something like this?

Response time is not a big issue; this will probably run once a day.

Thanks and regards, ~Ray
0
Comment
Question by:Ray Paseur
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
mankowitz earned 500 total points
ID: 39598081
Ray-

Never thought I'd be answering one of your questions, but here goes:

Look at the max_allowed_packet variable to see how big a query you can submit. However, my guess is that you could probably make a query like WHERE id < 20000 in many cases.

SHOW VARIABLES LIKE 'max_allowed_packet';

Open in new window

0
 
LVL 108

Author Comment

by:Ray Paseur
ID: 39598131
Great!  That's exactly what I was looking for.

stdClass Object
(
    [Variable_name] => max_allowed_packet
    [Value] => 33554432
)
0
 
LVL 108

Author Closing Comment

by:Ray Paseur
ID: 39598132
Many thanks! ~Ray
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now