1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravelで3000行程度でinsert上限になってしまった件

Posted at

Laravelか、MySQLの仕様かは分かりませんが、データベースに10000行ほどなのでループではなくてinsertで一括保存をしようとして、はまりました。

勝手に、数万行くらいinsertできるものという謎の思い込みがあり、「やっぱ思い込みはよく無いよね」という話と、「エラーログが最強だよね」という話。

あるデータをinsertで一括保存しようとしたが、なぜか3200行を超えるあたりでエラーになる。
foreachでならエラーが起きないし、3277列目がエラーの起点だったのですが、3277を単一指定で保存しようとすると成功する。

この時点で、上限が頭に思い浮かぶも、「いや、現代においてたった3000行程度で上限なわけない!と違う理由を探す。

ここで、ひどいことに、このクラスはキューで処理をしていたので、phpのエラーログを見るのが面倒で、面倒くさがってゴチャゴチャいろんなトライをしていたんですね。

でも、ダラダラと3日目に入り、キューではなくページでルートを作り直してみると、、、

laravel Prepared statement contains too many placeholders

というなんとも分かりやすいエラーが。。

このように、1000行ずつに分けてinsertすることであっさり解決しましたとさ。

素人は、思い込むべからず。

面倒くさがらずに、エラーログを見るべし。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?