Question

I ran an update query joining across a huge number of tables that updated one field, and it matched 29k some-odd rows. Running the same query with only an addition in the Set clause increased the matched rows to 118k some-odd rows. It seems this should only change if the WHERE clause were edited.

Was it helpful?

Solution

I think I just figured it out...

MySQL must count the number of rows that will be updated, not all the ones that will be generated by the join that happens during the update. The difference being that if there are many [B] to one [A], and many [C] to one [B], joining all would create n([C]) rows, but updating [B] would only count n([B]). Adding a set for [C] makes this number n([B]) + n([C]).

Since the fields in the set clause are on different tables, it changes the number updated.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top