C
C#•10mo ago
Bulelani Botman

How Can I Pull 900K Records From My Database & Not Have The Page Slow Down When Rendering The Record

I have a project that is pulling 900K records from a database & displaying them to a view. Whenever I pull these records, I get a connection timeout error. I fixed that by pulling the top 50000 records, it works but then I have a problem that it takes time to fully display the page. I also have a problem that I'm displaying these records using DataTables & takes time to load the JavaScript. How can I fix this?
39 Replies
Angius
Angius•10mo ago
Whyever would you be pulling this many records all at once...? Use pagination
Pobiega
Pobiega•10mo ago
rendering 900K records in a datatable will never ever be fast lol and also entirely useless if you ask me its just too much data to meaningfully work with in a browser/manually you could offer an export of data instead
Bulelani Botman
Bulelani BotmanOP•10mo ago
It's required for the user to see all these records & choose which ever record they want to use
Angius
Angius•10mo ago
Hw would they be even able to pick one record out of 900k lmao You can't even read that many and parse them
Bulelani Botman
Bulelani BotmanOP•10mo ago
Can you redirect me to where I can learn about this lmao! i figured it out the hard way
Angius
Angius•10mo ago
Are you using EF or raw SQL?
Bulelani Botman
Bulelani BotmanOP•10mo ago
mhhh! maybe export the data to an excel file or so? they will search using an ID & the datatable will filter the records because it has this feature
Angius
Angius•10mo ago
Filter when fetching the data Search when fetching the data
Pobiega
Pobiega•10mo ago
yeah, CSV would be a solid choice and works with excel
Bulelani Botman
Bulelani BotmanOP•10mo ago
one solution is pagination, how does this work?
Pobiega
Pobiega•10mo ago
and yeah, if the user alreayd knows the ID, just have them enter it before you fetch the data
Angius
Angius•10mo ago
You get the first 50 records Then the second batch of 50
Pobiega
Pobiega•10mo ago
pagination just "chunks" the results into managable bits - it will not help in this case
Angius
Angius•10mo ago
Third batch of 50 and so on Requested by the user
Bulelani Botman
Bulelani BotmanOP•10mo ago
Raw SQL, I used EF but then i needed to pull from multiple databases so i turned to raw SQL
Pobiega
Pobiega•10mo ago
pagination is for browsing data, not searching for it
Angius
Angius•10mo ago
Well, yeah The query will search for the data and filter/sort it
Bulelani Botman
Bulelani BotmanOP•10mo ago
no! after the data is fully loaded
Angius
Angius•10mo ago
But pagination will help display it, should the filtered search results be a lot Why?
Bulelani Botman
Bulelani BotmanOP•10mo ago
i did work on this feature, i will try to implement it again on this project ohhh! search before loading the data is there a sql script for using pagination?
Angius
Angius•10mo ago
LIMIT and OFFSET
Bulelani Botman
Bulelani BotmanOP•10mo ago
no, i think i will revert back to just searching for the specific data that a user wants & display that record rather than requesting all 900k records
Angius
Angius•10mo ago
Or, in some databases, just LIMIT with two parameters
Bulelani Botman
Bulelani BotmanOP•10mo ago
ohhhh! i will try to use it. so, i assume when you press the next button in the view it will go back to the sql script and laod the next batch?
Angius
Angius•10mo ago
Yes
Bulelani Botman
Bulelani BotmanOP•10mo ago
well, thank you for explaining this scenario. it absolutely helped me
Henkypenky
Henkypenky•10mo ago
if you want to simulate that you actually pulled off 900k records you can do a count and show the amount of records like: Viewing 1-50 of 999.999 records. You can also simulate paging if u want, like show 1,2,3.......890 with arrows
Bulelani Botman
Bulelani BotmanOP•9mo ago
the datatable plugin has the pagination feature, if you are pulling lets say 10k records it will automatically do it for you but my issue is behind the scenes which is my SQL code. I am using
SELECT * FROM LIS
SELECT * FROM LIS
which pulls all the columns and the records from this table and I get the connection timeout from MSSQL Server because pulling a lot of data at once & trying to display it
Pobiega
Pobiega•9mo ago
I mean, we discussed this when you first asked - pagination is for browsing data. You cant meaningfully browse 900K records do the search before load thing we discussed.
Bulelani Botman
Bulelani BotmanOP•9mo ago
yes, i was just telling him that the datatables plugin does pagination for me but my problem is just the connection timeout!
Pobiega
Pobiega•9mo ago
command timeout you mean?
Bulelani Botman
Bulelani BotmanOP•9mo ago
i did implement the search feature but on another page it's just not suitable. i need to pull all those records whether i like it or not and the user just can't search because he doesn't know the information / doesn't have the info because this table is just filled with properties that are about 900K
Pobiega
Pobiega•9mo ago
connection timeout is different 🙂
Bulelani Botman
Bulelani BotmanOP•9mo ago
i am lost with this one, what does do?
Pobiega
Pobiega•9mo ago
connection timeout is how long the client waits to establish the connection to the server command timeout is how long it waits for a command to run
Bulelani Botman
Bulelani BotmanOP•9mo ago
okay, let me run & see what the error name is again so i can confirm
Angius
Angius•9mo ago
You can still do pagination, no?
Bulelani Botman
Bulelani BotmanOP•9mo ago
yes, i can do but with a limited number of records, 20K records max
Angius
Angius•9mo ago
Do it with even fewer items per page 50-100 is usually the maximum
Want results from more Discord servers?
Add your server