cycle / database

Database Abstraction Layer, Schema Introspection, Schema Generation, Query Builders
MIT License
53 stars 22 forks source link

🐛 Memory leak on batch insert #136

Closed gam6itko closed 8 months ago

gam6itko commented 9 months ago

No duplicates 🥲.

Database

MySQL

What happened?

I use DatabaseInterface::execute to batch insert. I detect a huge memory leak if queryCache: true.

The problem is that the number of VALUES may differ, and each time the request is cached.

I create demo-project with demo of issue: https://github.com/gam6itko/spiral-app-sandbox/blob/cb97213a8c12f7e98ae4186d3e90f2d8b2b09bea/src/app/app/src/Command/CycleMemoryLeakCommand.php#L49

image

Version

database 2.5.2
PHP 8.1
roxblnfk commented 8 months ago

Now it is available to disable driver query cache before any request. We are thinking about automatic disabling cache in batch insert case but I'm not sure that it will be implemented.

Release is coming.

roxblnfk commented 8 months ago

We decided not to add heuristics to the execute method. Therefore, simply use the $driver->withoutCache() method before executing queries that do not need to be cached.