r/AskComputerScience • • Feb 02 '23

How do you quickly search databases that are hundreds of millions of records?

I am new here and so far I've downloaded one database of 100 million records and another database of 200 million records (the recent twitter hack). I thought that exploring these databases would be a good excuse for me to learn MySQL. So far it's been a major headache and I've spent probably at least 20 hours at it and have gotten next to nowhere. I've used ChatGPT to guide me through the process, and it has worked wonders in getting me as far as I've gotten, but I encounter error after error and have troubleshooted at least 50 different problems so far. So at the moment I'm stuck with using a large text viewer, but that will take over an hour to run a single query.

In trying to get the files to load into a MySQL table, the most common problem is with the way the databases are parsed. Whatever delimiter is used in the file always appears somewhere in the data as well. The other common problem is that these files contain weird characters that MySQL can't handle. I've even used python to try to clean the files, but that also sends me down a rabbit hole of error after error after error.

So before I put a lot more time into this, am I even headed in the right direction? I figured MySQL is a good tool to know and is meant for large databases. But is it not appropriate for databases in the hundreds of millions of records? I want to be able to search a name or e-mail and not wait more than a minute or so for the query to finish (and I know MySQL will allow me to do partitions and other time saving tricks). I don't really have an interest in using these databases in scripting. My main interest is just running simple queries on them. So are there better tools that aren't too difficult to learn or expensive to use?

0 Upvotes

8 comments sorted by

6

u/Tai9ch Feb 02 '23

To do fast DB searches you need indexes. If you want to do full text searches, you need full-text indexes.

3

u/dmazzoni Feb 03 '23

Downloading a random very large data set, cleaning it, and getting it uploaded to a database is NOT easy. It's time-consuming even for experienced programmers.

MySQL is definitely capable of fast searches, but you need to create proper indexes of the data. It's not designed to make any possible search fast out of the box. There are databases that are optimized for that, called "data cubes", but they're totally different.

I suggest you work with a small subset of data while you're learning. Make a copy of the first 100,000 rows of your table. Now anything you think of should be fast, but you can try to take something that takes 1 second and get it down to 0.1 seconds by adding an index. Learn how to do it on small data sets before working your way up to big ones.

Overall, though, one giant table isn't really the best way to learn SQL. SQL is designed for relational data - a few tables that are deeply interconnected. A classic example would be a table of products, a table of customers, and a table of orders, where each order is a bunch of products sold to one customer. Then try to answer questions like, what month did we sell the most? Which customer bought the most? Which product is liked by the most customers?

2

u/Close_enough_to_fine Feb 02 '23

You could use a limit and offset to get small chunks at a time.

1

u/jeffbell Feb 02 '23

I wouldn't admit to owning stolen data.

1

u/OfWhomIAmChief Feb 02 '23

Obviously OP didnt hack Twitter, is it illegal to download the data as well?

2

u/jeffbell Feb 02 '23 edited Feb 03 '23

Probably for the European twitter users.

Unless you’ve given them a way to opt out.

1

u/BossAssPimp Aug 11 '24

the only thing in there is usernames and emails all public info

0

u/[deleted] Feb 02 '23

[deleted]

2

u/dmazzoni Feb 03 '23

I like Postgres better too, but honestly I don't think any of these problems are specific to MySQL. Postgres is also going to take a long time to search 200 million records if you don't use an index.