search
HomeDatabaseMysql Tutorial辛星解读mysql中的存储过程的优劣_MySQL

我们常用的SQL语句在执行的时候需要首先进行编译,然后执行,而存储过程则是一组为了完成特定功能的SQL语句集,它直接编译好了存储在数据库中,用户通过指定存储过程的名字即可调用该存储过程。

存储过程的优点主要包括以下几点:

第一点,性能提高。这是相对于不适用存储过程来说的,因为存储过程在创建的时候就编译好了,而后每次调用都不会再次编译,这相对于传统的SQL语句中每次调用都需要编译的情况来说,性能提高了何止一点两点。

第二点,重用性强。存储过程使用名字即可使用,也就是传说中的“一次编写,随便调用”。这样不仅提高了重用性,还减少了出错的几率,也会加快开发速度,可以说是一件非常好的事情。

第三点,减少网络流量。这一点对于小数据量的时候一般体现不出来,那么当数据量较大的时候,我们会发现由于使用存储过程比使用SQL语句会使用更少的字节数,因此它会降低传输的数据量。

第四点,安全性提高。由于存储过程也可以使用权限控制,而且参数化的存储过程可以防止SQL注入攻击,也在一定程度上保证了安全性。

第五点,灵活性增强。由于存储过程可以使用流程控制语句来编写,导致它有着很强的灵活性,可以根据实际情况来执行不同的SQL语句,而不是只能单纯的简单的执行命令。而且该存储过程还可以修改其逻辑而其他部分不用改变,也就是说,我们的表的结构改变了,我们只需要修改相应的存储过程即可,我们的Java或者PHP等程序不需要改变。

第六点,当业务复杂的时候,存储过程会减少工作量,为什么呢,原因很简单,如果我们不适用存储过程,那么就会导致我们先从数据库中取出来数据,然后经过计算,再放入到数据库中,这个开销还是蛮大的,这中间的开销包括我们的Java或者PHP程序连接数据库获取结果集等若干操作,如果我们使用了存储过程,那么就没有那么多事了,直接在mysql内就搞定了。

好,上面说完了存储过程的优点,当然存储过程也肯定有它的缺点,下面是它的几个缺点:

第一点,工作量加大。这里并不是说我们把程序该做的事让mysql去做不好,而是mysql本身并没有很像样的IDE来开发我们的存储过程,我们很多时候还是需要手写,这样就会比较麻烦,而且存储过程的调试也是一个问题,没有很像样的调试工具。

第二点,优势不明显。运行速度上,对于大多数的语句缓存来说,编译sql的时间开销并不是很大,但是执行存储过程还需要检查权限等一些其他开销,所以,对于很简单的sql,存储过程并没有很大优势。

第三点,赘余功能。对web程序来说,我们连接数据库的用户往往就是同一个,不需要太多的安全机制,所以,对于安全上的检测看上去很好,实际上优点多余。

第四点,小型程序完全无用。对于小型web应用来说,它的使用价值就更小了,反而会拖累开发进度。

第五点,对于运维上。当我们的程序要更换数据库的时候,它的移植性相对于不适用存储过程要复杂一些,对于维护上,由于是在db端,因此比server端的程序更好维护一些。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Reduce the use of MySQL memory in DockerReduce the use of MySQL memory in DockerMar 04, 2025 pm 03:52 PM

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

How to solve the problem of mysql cannot open shared libraryHow to solve the problem of mysql cannot open shared libraryMar 04, 2025 pm 04:01 PM

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

How do you alter a table in MySQL using the ALTER TABLE statement?How do you alter a table in MySQL using the ALTER TABLE statement?Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Run MySQl in Linux (with/without podman container with phpmyadmin)Run MySQl in Linux (with/without podman container with phpmyadmin)Mar 04, 2025 pm 03:54 PM

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

What is SQLite? Comprehensive overviewWhat is SQLite? Comprehensive overviewMar 04, 2025 pm 03:55 PM

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

Running multiple MySQL versions on MacOS: A step-by-step guideRunning multiple MySQL versions on MacOS: A step-by-step guideMar 04, 2025 pm 03:49 PM

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

How do I configure SSL/TLS encryption for MySQL connections?How do I configure SSL/TLS encryption for MySQL connections?Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor