reading from MySQL is faster or reading from a fil

2020-04-07 18:36发布

HI

I got a doubt I have seen reading mysql data is slower in case of large tables...I have done lots of optimization but cant get through..

what I am thinking is will it give a better speed if I store data in a piece of file??

off course each data will be a separate file. so millions of data = millions of file. I agree it will consume the disk space... but what about reading process?? is it faster??

I am using PHP to read file...

标签: php mysql file
7条回答
够拽才男人
2楼-- · 2020-04-07 19:08

Reading one file = fast.

Reading many / big files = slow.

Reading singular small entries from database = waste of I/O.

Combining many entries within the database = faster than file accesses.

查看更多
Summer. ? 凉城
3楼-- · 2020-04-07 19:10

Reading from a dbms (MySQL is one) is faster in most cases, because they have built in cache that will keep the data in memory, so next time you try to read the same data, you will not have to wait on the incredible slow hard drive.

A dbms is essentially reading from your hard drive + a cache to speed things up (+ some data sorting algorithms). Remember, your database is stored on your hard drive :)

查看更多
可以哭但决不认输i
4楼-- · 2020-04-07 19:18

To answer the topic, yes.

By which I mean that there are so many (unmentioned) factors that it's impossible to unequivocally state that one will be faster than the other every time.

查看更多
迷人小祖宗
5楼-- · 2020-04-07 19:18

It depends on what kind of data you're storing. Structured data is usually much faster and more flexible/powerful to read using SQL, since that's exactly what its made for. If you want to search, filter, sort or group by a certain attribute, the index structures and optimizations of a DBS are appropriate.

However, when using a DB for storing large files (BLOBs), which contain unstructured data in the sense that you are not going to search, filter, sort or group by any part of the files, then these files just blow up the database size and make it slow. There is an interesting study by Microsoft on this topic (just have to find the link yet). This study is the reason why Microsoft introduced the External BLOB storage in their SQLServer, which basically means what you asked: The BLOBs are saved in files outside the database, because they measured that access is much faster that way.

When storing files (e.g., pictures, videos, documents...) you often have some metadata on the file which you want to be able to use with a structured query language like SQL, while the actual files don't necessarily need to be saved in the database.

查看更多
趁早两清
6楼-- · 2020-04-07 19:19

As long as your tables are properly indexed and as long as you are using those indices (that's right), using a relational DB (like mysql) is going to be much faster, more robust, flexible (insert many buzzwords here), etc.

To examine why your queries' performance does not match your expectations, you can use the explain clause with your selects (http://dev.mysql.com/doc/refman/5.1/en/explain.html).

查看更多
男人必须洒脱
7楼-- · 2020-04-07 19:23

By choosing a custom file storage system you will lose the benefits of using a relational database. Also your code might not be easy maintainable.

Nonetheless, there are many who believe that relational databases offer too much complexity at the cost of speed. Have a look at the NoSQL entry in wikipedia and read about possible alternatives.

查看更多
登录 后发表回答