当前位置:网站首页>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
边栏推荐
- Using quartz under. Net core -- a simple trigger of [7] operation and trigger
- AIOT产业技术全景结构-数字化架构设计(8)
- XTask与Kotlin Coroutine的使用对比
- Using quartz under. Net core -- job attributes and exceptions of [4] jobs and triggers
- ClickHouse-数据类型
- Oninput one function to control multiple oninputs (take the contents of this input box as parameters) [very practical, very practical]
- Promise (IV)
- Using quartz under. Net core -- operation transfer parameters of [3] operation and trigger
- Using quartz under. Net core -- preliminary understanding of [2] operations and triggers
- Aiot industrial technology panoramic structure - Digital Architecture Design (8)
猜你喜欢
【生活中的逻辑谬误】稻草人谬误和无力反驳不算证明
Use between nodejs modules
Milvus 2.0 质量保障系统详解
Milvus 2.0 détails du système d'assurance de la qualité
[registration] tf54: engineer growth map and excellent R & D organization building
Go language, array, string, slice
Grpc gateway based on Ocelot
Simulation of infrared wireless communication based on 51 single chip microcomputer
. net cross platform principle (Part I)
[logical fallacy in life] Scarecrow fallacy and inability to refute are not proof
随机推荐
JS, entries(), keys(), values(), some(), object Assign() traversal array usage
[simple understanding of database]
Use between nodejs modules
Read a blog, re understand closures and tidy up
[batch change MySQL table and corresponding codes of fields in the table]
Change Oracle to MySQL
Grpc gateway based on Ocelot
On lambda powertools typescript
Go language RPC communication
Lock lock
Node template engine (EJS, art template)
Metaprogramming, proxy and reflection
Redis docker installation
Shell - introduction, variables, and basic syntax
C# Task. Delay and thread The difference between sleep
Use of shell sed command
手写事件发布订阅框架
Calculation formula related to tolerance analysis
ClickHouse-SQL 操作
Shortcut keys (multiline)