Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Boldozar's avatar

dealing with huge tables

im working on polls script i have 3 tables which are polls , options , answers i have 942 poll ,, 10 options for each poll ,, and around 5000 answer for each option in the problem comes with calling data using eager loading the request takes too long ,, any ideas for optimizing the script?

0 likes
11 replies
Snapey's avatar

Thats not huge. Huge is 10s of millions (or more!)

Sounds like though you might be trying to work with too much in memory at once.

Thats about all we can help with without more detail

Snapey's avatar

Well what are you trying to load from the database?

Boldozar's avatar

@Snapey im trying to get all polls with all it's options and answers using eager loading,, here is the using Poll::with('options','answers')->get()

Cronix's avatar

More than likely this comes down to your database design, and how things are indexed. Are all of your foreign keys indexed? That's the main thing. Are things you are using in where statements indexed? It would help to show the schema of the tables involved.

Cronix's avatar

Poll::with('options','answers')->get()

And why would you load 942 polls, along with all of their options/answers in a single request? Normally you'd use pagination and only load like 10 or whatever at a time? That's crazy lol.

Snapey's avatar

Like I say, trying to load too much into memory. Why do you need all polls in memory at once?

What is the business problem you are trying to solve?

1 like
Boldozar's avatar

@Cronix im using datatables so it handle the loading data ,, im not loading all data once :D any way thanks for help

@Snapey Thanks for help

Please or to participate in this conversation.