I’m new to MySQL, and I have a question about the memory.
I have a 200mb table(MyISAM, 2,000,000 rows), and I try to load all of it to the
memory.
I use python(actually MySQLdb in python) with sql: SELECT * FROM table.
However, from my linux “top” I saw this python process uses 50% of my memory(which is total 6GB)
I’m curious about why it uses about 3GB memory only for a 200 mb table.
Thanks in advance!
There’s nothing inherently wrong with what you’re doing. If memory usage is expanding with the size of the query, then one of a few things is happening:
Note that the underlying library may cache a certain amount of data, and you may see a significant amount of memory use as a result, but unless something is catastrophically wrong with the configuration it shouldn’t be 3GB.
Here’s some simple SQLite code that reproduces what you’re doing. When run, it creates a trivial table of fifteen million rows, which is about 180 MB on disk for the version I’m using. It then SELECTs all of this data, throwing away the results, and sleeps so you can examine the result. The resulting process, on my system, uses only 15 MB.
(Note that I ran the
create_dbandread_dbpasses with separate invocations; creating the database takes some time.)SQLite can handle this, and any production server-backed database like MySQL and Postgresql should be able to, too. SELECT results are a data stream, and databases should be able to handle streams of unlimited size easily.
This doesn’t answer your question, but I wanted to make it clear that there’s nothing wrong with what you’re doing–you should not need to manually chunk queries, though in the end that’s probably the workaround you’ll need.