Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's faster: temporary SQL tables or Python dicts for session data?

Have some programming background, but in the process of both learning Python and making a web app, and I'm a long-time lurker but first-time poster on Stack Overflow, so please bear with me.

I know that SQLite (or another database, seems like PostgreSQL is popular) is the way to store data between sessions. But what's the most efficient way to store large amounts of data during a session?

I'm building a script to identify the strongest groups of employees to work on various projects in a company. I have received one SQLite database per department containing employee data including skill sets, achievements, performance, and pay.

My script currently runs one SQL query on each database in response to an initial query by the user, pulling all the potentially-relevant employees and their data. It stores all of that data in a list of Python dicts so the end-user can mix-and-match relevant people.

I see two other options: I could still run the comprehensive initial queries but instead of storing it in Python dicts, dump it all into SQLite temporary tables; my guess is that this would save some space and computing because I wouldn't have to store all the joins with each record. Or I could just load employee name and column/row references, which would save a lot of joins on the first pass, then pull the data on the fly from the original databases as the user requests additional data, storing little if any data in Python data structures.

What's going to be the most efficient? Or, at least, what is the most common/proper way of handling large amounts of data during a session?

Thanks in advance!

like image 588
Rus925 Avatar asked Apr 11 '26 01:04

Rus925


1 Answers

Aren't you over-optimizing? You don't need the best solution, you need a solution which is good enough.

Implement the simplest one, using dicts; it has a fair chance to be adequate. If you test it and then find it inadequate, try SQLite or Mongo (both have downsides) and see if it suits you better. But I suspect that buying more RAM instead would be the most cost-effective solution in your case.

(Not-a-real-answer disclaimer applies.)

like image 173
9000 Avatar answered Apr 13 '26 14:04

9000