Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on In MySQL is there a limit to the number of keys in a IN() clause?

Post

In MySQL is there a limit to the number of keys in a IN() clause?

+3
−0

I have a PHP program that does a SELECT and then updates some of the values based on an algorithm.

Rather than updating one row at a time

UPDATE example_table 
SET COLUMN_A = 1 
WHERE primary_key_column = 10;

I was thinking of doing many updates at once like

UPDATE example_table 
SET COLUMN_A = 1 
WHERE primary_key_column IN(1,2,3,4,5);

The SELECTS are pulling in 100,000 rows at a time and to start with every single one of them may need to be updated, am I going to run into a limit of values in the IN() clause?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

General comments (3 comments)
General comments
ghost-in-the-zsh‭ wrote about 4 years ago

Another alternative is to try and set up all the SQL statements as a single transaction. Did you look into this?

Canina‭ wrote about 4 years ago

@ghost-in-the-zsh Considering that OP said in a comment to my answer that the point is to not "lock up the DB for a while", I doubt doing it in a transaction would meet the (originally unstated) requirement.

ghost-in-the-zsh‭ wrote about 4 years ago · edited about 4 years ago

@Canina I saw it. In MySQL, if you use InnoDB as the storage engine, then the only things getting locked during write operations are the rows being updated, not the tables themselves as a whole like MyISAM does. (And no one should be using MyISAM as the storage engine nowadays, since it's not even ACID-compliant.)