Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does more data mean slower queries?

Let's say I have one table that has 1000 rows and the other table with the same structure/index but 10 million records. Will the performance of CRUD operations on the bigger table be slower than the smaller one? Thanks.

like image 877
adityaw Avatar asked Mar 10 '09 08:03

adityaw


People also ask

What makes queries slow?

WAITING: Queries can be slow because they're waiting on a bottleneck for a long time. See a detailed list of bottlenecks in types of Waits. RUNNING: Queries can be slow because they're running (executing) for a long time. In other words, these queries are actively using CPU resources.

What makes a query faster?

The way to make a query run faster is to reduce the number of calculations that the software (and therefore hardware) must perform. To do this, you'll need some understanding of how SQL actually makes calculations.

What affects query speed?

Query performance also depends on data volume and transaction concurrency. Executing the same query on a table with millions of records requires more time that performing the same operation on the same table with only thousands of records. A lot of concurrent transactions can degrade SQL Server performance.

Does limit make query faster?

The answer, in short, is yes. If you limit your result to 1, then even if you are "expecting" one result, the query will be faster because your database wont look through all your records. It will simply stop once it finds a record that matches your query.


3 Answers

Depends on the database engine, but generally yes, it will be slower, simply because you have to wade through index to find your data. If your making a global update, it will also be slower, simply because you're changing more data.

Databases are also often tuned towards either fast write or fast read - in the second case you have to update index, which takes more time, once it is big.

like image 134
user76035 Avatar answered Nov 11 '22 04:11

user76035


It depends. Creating, Deleting and Updating will be slightly slower in average since it is more likely that index structures will have to be reorganized. Also, if more data is frequently requested from the database system, then it is less likely that the data you are trying to access in cached in RAM and must be read from the hard disc. But these differences should not be very significant for modifying queries.

Fetching/Reading will certainly be slower though. It is just obvious that having to fetch, filter, sort and group large amounts of data is slower than doing the same with small amounts. This is especially true if the data you are working on is too large to fit into the machine's RAM.

like image 41
Ferdinand Beyer Avatar answered Nov 11 '22 06:11

Ferdinand Beyer


That depends on so many factors that it's almost impossible to say. Example: The DB engine stores data as rows which have pointers to the strings. For some reason, your 10M rows table only contains four different strings. So you have 10M pointers to four strings.

An update to replace one string with another would actually only replace one string with another; the pointers would be the same. No need to update the indexes, either. Same speed no matter how many rows you have.

Delete would be slower unless delete just flags the string as "deleted". A cleanup process running some time later would then actually clean the table. But you, as a user of the database, won't notice: The delete returns immediately.

Select would be slower since it has to return more data. The time until the first row can be returned will depend a lot on the engine design and your query. A well written query running against a 10M table with well chosen indexes can be faster than one against a 1K table with bad indexes. It depends on the amount of RAM on the server (maybe it can keep the whole database in RAM), disk speed (RAID array with lots of disks that can work in parallel versus a slow PC with little RAM and a single disk).

Insert is usually slower since you will have more (and bigger) indexes on the 10M table but if you have no indexes, adding a single row to a 10M table is usually as fast as adding to a small table.

like image 1
Aaron Digulla Avatar answered Nov 11 '22 06:11

Aaron Digulla