当前位置:网站首页>Compare the performance of query based on the number of paging data that meet the query conditions
Compare the performance of query based on the number of paging data that meet the query conditions
2022-04-23 17:20:00 【I know why you're here】
Form writing habits together ! This is my participation 「 Nuggets day new plan · 4 Yuegengwen challenge 」 Of the 21 God , Click to see the event details .
Antecedents feed
-
As a front end , We don't just have to be able to write pages , Interface , Sometimes we need to use node To write some interfaces for the project . As the most common list interface , I believe we are all familiar , After all, this is the most commonly used .
-
Ordinary list interfaces generally have conditional search , Pagination, etc . And as paging , As image java Such a big brother , The ecology is complete , General framework will help you do paging query , You don't need to do more by yourself .
-
And as a newborn Nodejs, Although some frameworks are available , But I still prefer to write by myself sql sentence , And this is the time to encounter a problem : It is during list query , Usually, we need to return the number of qualified data to the front end .
-
After unremitting efforts, we found two solutions
- One is to query paging data , Execute another statement to query all the conditions , Then get the total . It needs to be performed twice sql sentence .
- One is through SQL_CALC_FOUND_ROWS Complex queries , Get paging data and total number at the same time . There are two statements , But there is only one implementation .
Comparison of solutions
I am here Navicat Premium Two statements are used on the tool to 1k、10k、100k、1000k、10000k The amount of data tested .
-
The first statement template is :select * from xxx limit 1,1000;select COUNT(*) from xxx;
-
The second statement template is :select SQL_CALC_FOUND_ROWS * from xxx;select FOUND_ROWS() total;
-
notes : The above example is just an ordinary query statement , If you use a connected table , Multi table query, etc , You can change it yourself .
-
Simply use tools to query , Of the query sql Statement is a join table query : give the result as follows
- 1k data :
-
The result of the first scheme :
-
The result of the second scheme :
-
- 10k data :
-
First option :
-
Second option :
-
- 100k data
- First option :
- Second option :
- First option :
- 1000k data
- The first solution :
- The second solution :
- The first solution :
- 10000k data
- The first solution
- The second solution :
- The first solution
- 1k data :
-
summary : According to the above results, we can see , Without considering the specific connection mode of the actual back-end to the database , Complex query, that is, the first query method, takes several times as long as non complex query .
summary
- Model :MacBook pro m1pro chip ,10 Core CPU ,16G Memory .
- The above experiments are used when generating data npm-mysql Package to connect to the database , And insert data . The connection method is connection pool .
- Then it will combine mysql package , and mysql2 Package and real node Compare the two ways of connecting data query .
- The above experimental data are not enough to generalize , But it also has reference value . If other students have any suggestions, please speak enthusiastically .
- I hope the comment area is a peaceful technical exchange , Comments with strong personal negative emotions will be deleted .
版权声明
本文为[I know why you're here]所创,转载请带上原文链接,感谢
https:https://yzsam.com/html/pBbJso.html
边栏推荐
- Shell-sed命令的使用
- RPC核心概念理解
- Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers
- Shell-cut命令的使用
- Baidu Map 3D rotation and tilt angle adjustment
- Come out after a thousand calls
- Websocket (basic)
- . net type transfer
- Error in v-on handler: "typeerror: cannot read property 'resetfields' of undefined"
- Using quartz under. Net core -- preliminary understanding of [2] operations and triggers
猜你喜欢
Milvus 2.0 détails du système d'assurance de la qualité
Further study of data visualization
Use of five routing guards
. net type transfer
[PROJECT] small hat takeout (8)
groutine
Nacos + aspnetcore + Ocelot actual combat code
[registration] tf54: engineer growth map and excellent R & D organization building
JS, entries(), keys(), values(), some(), object Assign() traversal array usage
[WPF binding 3] listview basic binding and data template binding
随机推荐
Baidu Map Case - modify map style
2. Electron's HelloWorld
Shell-sort命令的使用
Lock lock
RPC核心概念理解
ASP. Net core dependency injection service life cycle
Deep understanding of control inversion and dependency injection
VLAN advanced technology, VLAN aggregation, super VLAN, sub VLAN
freeCodeCamp----shape_ Calculator exercise
SiteServer CMS5. 0 Usage Summary
Go language, array, string, slice
Indexes and views in MySQL
Shell script -- shell programming specification and variables
自定义my_strcpy与库strcpy【模拟实现字符串相关函数】
线性代数感悟之2
Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers
1-1 NodeJS
Paging SQL
How to use the input table one-way service to send (occupy less) picture files (body transmission)? FileReader built-in object involved
Scope and scope chain in JS