CN110968595A - Single-thread sql statement execution method, equipment and storage medium - Google Patents
Single-thread sql statement execution method, equipment and storage medium Download PDFInfo
- Publication number
- CN110968595A CN110968595A CN201911181619.6A CN201911181619A CN110968595A CN 110968595 A CN110968595 A CN 110968595A CN 201911181619 A CN201911181619 A CN 201911181619A CN 110968595 A CN110968595 A CN 110968595A
- Authority
- CN
- China
- Prior art keywords
- sql statement
- queue
- sql
- thread
- execution method
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 27
- 238000004590 computer program Methods 0.000 claims description 8
- 230000015556 catabolic process Effects 0.000 abstract description 2
- 230000001133 acceleration Effects 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2453—Query optimisation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/28—Databases characterised by their database models, e.g. relational or object models
- G06F16/284—Relational databases
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/546—Message passing systems or structures, e.g. queues
Abstract
The invention discloses a single-thread sql statement execution method, equipment and a storage medium, wherein the execution method comprises the following steps of S1: creating a first-in first-out queue, and sequentially writing a plurality of sql statements into the queue; step S2: creating a sub-thread, wherein the sub-thread is connected with a database; step S3: fetching one of the sql statements from the queue; step S4: sending the retrieved sql statement to the database for execution through the sub-thread, and deleting the executed sql statement; step S5: looping the steps S3-S4 until the queue is empty. The invention combines a plurality of sql execution statements generated by the service under multiple threads under one thread, and executes the sql in a circulating way one by one, thereby preventing the fault of system breakdown caused by instant request peak and improving the system stability.
Description
Technical Field
The invention relates to the technical field of database acceleration, in particular to a single-thread sql statement execution method, single-thread sql statement execution equipment and a single-thread sql statement execution storage medium.
Background
Currently, internet server applications usually read and write relational databases, such as mysql. And each time the business logic is executed, sending the sql statement generated by the business to the database for execution. If there are a large number of users using the internet application at the same time, the system will generate a large number of sql statements to be sent to the database for execution at the same time. Under high-concurrency multithreading, for executing a large number of sql statements, the read-write performance of the relational database is obviously reduced, and even the problems of response timeout, access denial, deadlock and the like are caused, and meanwhile, the normal operation of the system service is influenced.
Disclosure of Invention
In order to overcome the defects of the prior art, one of the objectives of the present invention is to provide a single-threaded sql statement execution method, which merges multiple sql execution statements generated by multiple threads of a service into one thread, and executes the sql statements cyclically one by one, so as to prevent a fault that an instantaneous request peak causes system crash, thereby improving system stability.
Another object of the present invention is to provide an electronic device.
It is a further object of the present invention to provide a storage medium.
One of the purposes of the invention is realized by adopting the following technical scheme:
a single-threaded sql statement execution method, comprising:
step S1: creating a first-in first-out queue, and sequentially writing a plurality of sql statements into the queue;
step S2: creating a sub-thread, wherein the sub-thread is connected with a database;
step S3: fetching one of the sql statements from the queue;
step S4: sending the retrieved sql statement to the database for execution through the sub-thread, and deleting the executed sql statement;
step S5: looping the steps S3-S4 until the queue is empty.
Further, after taking out one sql statement in step S3, determining whether the queue is empty, and if the queue is empty, waiting for a set time and then performing step S3; if not, step S4 is executed.
Further, the set time is a fixed time set by a user in a self-defined mode or generated by a default system.
Further, each sql statement is generated by its corresponding service request.
Further, the queue is connected with a service multithread, and the service multithread sequentially writes the generated sql statements into the queue.
Furthermore, the sequence of each sql statement entering the queue is determined by the service request proposing time corresponding to the sql statements.
Furthermore, the sequence of each sql statement entering the queue is determined by the priority level of the corresponding service request of the sql statements.
The second purpose of the invention is realized by adopting the following technical scheme:
an electronic device comprises a processor, a memory and a computer program stored on the memory and capable of running on the processor, wherein the processor realizes the single-thread sql statement execution method when executing the computer program.
The third purpose of the invention is realized by adopting the following technical scheme:
a storage medium having stored thereon a computer program which, when executed, implements the single-threaded sql statement execution method described above.
Compared with the prior art, the invention has the beneficial effects that:
on the premise of not influencing the service logic of the original system, a plurality of sql execution statements generated by the service under multiple threads are combined under one thread, and are circularly executed one by one sql, so that the problems of access rejection, deadlock and the like can not be caused due to the execution of the sql statements under a single thread, and the fault of system breakdown caused by instant request peak can be prevented, so that the system stability is improved.
Drawings
Fig. 1 is a schematic flow diagram of a single-threaded sql statement execution method according to the present invention.
Detailed Description
The present invention will be further described with reference to the accompanying drawings and the detailed description, and it should be noted that any combination of the embodiments or technical features described below can be used to form a new embodiment without conflict.
In the existing system, a plurality of business processes are directly connected with a database, and each business thread generates a corresponding sql statement according to a business request and directly sends the sql statement to the database for execution when a business logic is executed, so that the system may crash due to an instant request peak.
The single-threaded sql statement execution method in this embodiment can solve the above problem, so as to improve the stability of the system. As shown in fig. 1, the method comprises the steps of:
step S1: creating a first-in first-out queue, and sequentially writing a plurality of sql statements into the queue;
the FIFO queue is a set type based on a FIFO strategy, and the processing sequence of the elements in the queue is the sequence of the elements added into the queue; in this embodiment, the queue is connected to multiple service threads, each service thread generates an sql statement according to a service request, and a large number of sql statements are added to the queue, so that a large number of sql statements can be arranged in the queue in sequence, thereby avoiding high concurrency of a large number of sql statements and affecting the stability of the system.
When the service request is not finished, the generated sql statement is added to the queue in succession, and the time of the sql statement entering the queue is determined by the time of the service request; and when the service request is finished, no sql statement is generated, no new sql statement is added to the queue at the moment, and the queue is empty at the moment.
The sequence of each sql statement entering the queue can be determined by the plurality of sql statements according to the service request proposing time corresponding to the sql statements, namely, the service request proposing time is relatively earlier, and the corresponding generated sql statements can be preferentially written into the queue; and the service request is provided with relatively later time, and the corresponding generated sql statement is arranged behind the sql statement which is preferentially written into the queue.
In addition, the sequence of each sql statement entering the queue can be determined according to the priority level of the corresponding service request. The user can preset the priority level of each service request, the sql statement generated by the user with high priority level can be written into the queue preferentially, the sql statement generated by the user with low priority level is arranged behind the sql statement with high priority level.
Step S2: creating a sub-thread, wherein the sub-thread is connected with a database;
the sub-thread is connected with the database, the sql statements output from the queue can be sequentially transmitted to the database along the sub-thread for execution, and the problems of access rejection, deadlock and the like can not be caused due to the fact that the sql statements are executed under a single thread, and the fault that a system is crashed due to an instant request peak can be prevented.
Step S3: fetching one of the sql statements from the queue;
and extracting one sql statement from the queue according to the first-in first-out characteristic of the queue in sequence.
In addition, after taking out one sql statement, it is necessary to determine whether the current queue is empty, and if the queue is empty, step S3 is executed after waiting for a set time, that is, after waiting for the set time, one sql statement is extracted from the queue again, so that the sql statements sequentially added to the queue can still be extracted and executed; if not, it represents that there are sql statements to be executed in the queue, and then step S4 is executed.
In this embodiment, the set time is 0.5 seconds, that is, when the queue is empty, the sql statement is extracted from the queue again after waiting for 0.5 seconds, and if the queue is still empty, the sql statement is extracted again after waiting for 0.5 seconds until the service request is finished.
Step S4: and sending the fetched sql statements to the database for execution through the sub-thread, and deleting the extracted and executed sql statements in the queue, so that only unexecuted sql statements are arranged in the queue, and the execution of the sql is optimized.
Step S5: and looping the steps S3 to S4, and executing the sql statements in a loop one by one until the service request is completely finished, and stopping the loop until all the sql statements in the queue are completely executed.
Because the sql statement is executed under the single thread, the problems of access rejection, deadlock and the like cannot be caused, and the fault that the system is crashed due to the instantaneous request peak can be prevented.
Example two
An electronic device comprising a memory, a processor, and a program stored in the memory, the program configured to be executed by the processor, the processor implementing the steps of the single-thread sql statement execution method in one embodiment when executing the program.
In addition, the present invention also provides a storage medium, wherein the storage medium stores a computer program, and the computer program realizes the steps of the single-threaded sql statement execution method when being executed by a processor.
The invention is operational with numerous general purpose or special purpose computing system environments or configurations. For example: personal computers, server computers, hand-held or portable devices, tablet-type devices, multiprocessor systems, microprocessor-based systems, set top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like.
The device and the storage medium in this embodiment are based on two aspects of the same inventive concept, and the method implementation process has been described in detail in the foregoing, so that those skilled in the art can clearly understand the structure and implementation process of the system in this embodiment according to the foregoing description, and for the sake of brevity of the description, details are not repeated here. The above embodiments are only preferred embodiments of the present invention, and the protection scope of the present invention is not limited thereby, and any insubstantial changes and substitutions made by those skilled in the art based on the present invention are within the protection scope of the present invention.
Claims (9)
1. A single-threaded sql statement execution method, comprising:
step S1: creating a first-in first-out queue, and sequentially writing a plurality of sql statements into the queue;
step S2: creating a sub-thread, wherein the sub-thread is connected with a database;
step S3: fetching one of the sql statements from the queue;
step S4: sending the retrieved sql statement to the database for execution through the sub-thread, and deleting the executed sql statement;
step S5: looping the steps S3-S4 until the queue is empty.
2. The single-threaded sql statement execution method according to claim 1, wherein after one sql statement is fetched in step S3, it is determined whether the queue is empty, and if the queue is empty, step S3 is executed after waiting a set time; if not, step S4 is executed.
3. The single-threaded sql statement execution method of claim 2, wherein the set time is a fixed time that is set by a user or generated by a system default.
4. The single-threaded sql statement execution method of claim 1, wherein each sql statement is generated by its corresponding business request.
5. The single-threaded sql statement execution method according to claim 1, wherein the queue is connected to a service multithread, and the service multithread sequentially writes the generated sql statements into the queue.
6. The single-threaded sql statement execution method according to claim 1, wherein a plurality of sql statements determine an order in which each sql statement enters the queue according to a service request presentation time corresponding to the sql statement.
7. The single-threaded sql statement execution method according to claim 1, wherein a plurality of sql statements determine an order in which each sql statement enters the queue according to a priority level of a service request corresponding to the sql statement.
8. An electronic device comprising a processor, a memory, and a computer program stored on the memory and executable on the processor, wherein the processor implements the single-threaded sql statement execution method according to any one of claims 1 to 7 when executing the computer program.
9. A storage medium having stored thereon a computer program which, when executed, implements the single-threaded sql statement execution method of any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911181619.6A CN110968595A (en) | 2019-11-27 | 2019-11-27 | Single-thread sql statement execution method, equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911181619.6A CN110968595A (en) | 2019-11-27 | 2019-11-27 | Single-thread sql statement execution method, equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN110968595A true CN110968595A (en) | 2020-04-07 |
Family
ID=70031829
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201911181619.6A Pending CN110968595A (en) | 2019-11-27 | 2019-11-27 | Single-thread sql statement execution method, equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110968595A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113407562A (en) * | 2021-06-04 | 2021-09-17 | 北京金山云网络技术有限公司 | Communication method and device of distributed database system |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20070073655A1 (en) * | 2005-09-29 | 2007-03-29 | Ncr Corporation | Enhancing tables and SQL interaction with queue semantics |
CN105740344A (en) * | 2016-01-25 | 2016-07-06 | 中国科学院计算技术研究所 | Sql statement combination method and system independent of database |
US20170103096A1 (en) * | 2013-12-02 | 2017-04-13 | Teradata Us, Inc. | Enhancing tables and sql interaction with queue semantics |
CN106844589A (en) * | 2017-01-10 | 2017-06-13 | 深圳市爱立峰科技有限公司 | The asynchronous storage method of database data and system |
CN107391730A (en) * | 2017-08-02 | 2017-11-24 | 郑州云海信息技术有限公司 | A kind of SQL statement processing method and processing device |
CN109033381A (en) * | 2018-07-27 | 2018-12-18 | 郑州云海信息技术有限公司 | A kind of execution method, device and equipment of service request |
CN110121704A (en) * | 2016-12-30 | 2019-08-13 | 华为技术有限公司 | A kind of execution method, equipment and system for storing process |
-
2019
- 2019-11-27 CN CN201911181619.6A patent/CN110968595A/en active Pending
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20070073655A1 (en) * | 2005-09-29 | 2007-03-29 | Ncr Corporation | Enhancing tables and SQL interaction with queue semantics |
US20170103096A1 (en) * | 2013-12-02 | 2017-04-13 | Teradata Us, Inc. | Enhancing tables and sql interaction with queue semantics |
CN105740344A (en) * | 2016-01-25 | 2016-07-06 | 中国科学院计算技术研究所 | Sql statement combination method and system independent of database |
CN110121704A (en) * | 2016-12-30 | 2019-08-13 | 华为技术有限公司 | A kind of execution method, equipment and system for storing process |
CN106844589A (en) * | 2017-01-10 | 2017-06-13 | 深圳市爱立峰科技有限公司 | The asynchronous storage method of database data and system |
CN107391730A (en) * | 2017-08-02 | 2017-11-24 | 郑州云海信息技术有限公司 | A kind of SQL statement processing method and processing device |
CN109033381A (en) * | 2018-07-27 | 2018-12-18 | 郑州云海信息技术有限公司 | A kind of execution method, device and equipment of service request |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113407562A (en) * | 2021-06-04 | 2021-09-17 | 北京金山云网络技术有限公司 | Communication method and device of distributed database system |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US9384148B2 (en) | Detection of unauthorized memory modification and access using transactional memory | |
US8990510B2 (en) | Read-copy update system and method | |
CN110865888B (en) | Resource loading method and device, server and storage medium | |
US9830189B2 (en) | Multi-threaded queuing system for pattern matching | |
US20130160028A1 (en) | Method and apparatus for low latency communication and synchronization for multi-thread applications | |
US8763012B2 (en) | Scalable, parallel processing of messages while enforcing custom sequencing criteria | |
US10268610B1 (en) | Determining whether a CPU stalling a current RCU grace period had interrupts enabled | |
WO2020181810A1 (en) | Data processing method and apparatus applied to multi-level caching in cluster | |
US20150058855A1 (en) | Management of bottlenecks in database systems | |
KR20200135718A (en) | Method, apparatus, device and storage medium for managing access request | |
US8495589B2 (en) | Holding threads in a software debugger | |
US20160188243A1 (en) | Memory access protection using processor transactional memory support | |
US8769233B2 (en) | Adjusting the amount of memory allocated to a call stack | |
US10313477B2 (en) | System and method for use of a non-blocking process with a resource pool in a computing environment | |
CN111813520A (en) | Thread scheduling method and device, storage medium and electronic equipment | |
US8898124B2 (en) | Controlling database trigger execution with trigger return data | |
CN112181948A (en) | Database operation statement processing method and device, electronic equipment and medium | |
CN110968595A (en) | Single-thread sql statement execution method, equipment and storage medium | |
CN109002286A (en) | Data asynchronous processing method and device based on synchronous programming | |
US9164813B2 (en) | Using a debug engine to identify threads that wait for a mutex | |
CN108763421B (en) | Data searching method and system based on logic circuit | |
US7996401B2 (en) | Inserting new transactions into a transaction stream | |
US10565044B2 (en) | Message handling related to non-parallelizable functionality | |
US20220237073A1 (en) | Information processing apparatus, non-transitory computer readable medium storing program, and method | |
CN109800073B (en) | Real-time process scheduling method, device, terminal and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20200407 |
|
RJ01 | Rejection of invention patent application after publication |