今天在调一些固定的SQL,调整一下写法,加点注释,改几个别名什么的,本身没什么事情。 结果在其中某一个SQL的时候,忽然卡住了。一共是三个左连接一个EXISTS,每张表都不超过一百万行。按道理说,这种SQL就算慢,也不会超过一分钟,就得出结果。结果执行的
今天在调一些固定的SQL,调整一下写法,加点注释,改几个别名什么的,本身没什么事情。
结果在其中某一个SQL的时候,忽然卡住了。一共是三个左连接一个EXISTS,每张表都不超过一百万行。按道理说,这种SQL就算慢,也不会超过一分钟,就得出结果。结果执行的效果让我很困惑。头一次执行的时候很快,非常快,两秒出结果。再执行一次,就要很久了,反正我是没等到过结果。最长一次等了半小时,我中午饭都吃完了思密达。。。
看计划,没问题,一点问题都没有。看数据库的负载,也没什么问题。可以说库是很闲的。那这是为啥?能执行,能有速度快的,说明Oracle能找到基本正确的计划。但是为什么第二次会慢呢?一下子就想到了一个新特性,11g里对执行计划的新改进。
_OPTIMIZER_USE_FEEDBACK
简单可以理解为这是Oracle对CBO的一种持续改进。本身PLAN就是基于各种数据对实际执行时间的一种推测,COST也是基于一些算法得到的结果,不是一个确切的值。当Oracle执行过这个语句以后,可以在实际环境中得到一些采样结果,这些结果是实际跑出来的,不是推测或者算出来的。这些值比计算得到的COST和ROWS要来的靠谱的多,于是11g就打算用这些值来做动态推测,基于一个可信的执行计划的详细明细来得到更加贴切实际的计划改进。
但是俗话说的好,Oracle不到R2不要用,咳咳。。。
我的SQL就是被这个参数给搞了一下,Oracle依据首次执行的结果优化了,然后我郁闷了。。。
说说验证和解决办法吧。验证的话可以加HINT,OPT_PARAM(’_OPTIMIZER_USE_FEEDBACK‘,‘FALSE’)。如果加过以后,执行效果不再乱飘了,那么就去把这个隐含参数改成false吧。
提示一下,改隐含参数要加引号,写成“a“=b的样子,具体怎么改就不说了,能看到这里的人,改个参数还是会的,是吧。可以改session和system,都不用重启。
原文地址:11g新特性之忽快忽慢的执行速度, 感谢原作者分享。

MySQLoffersvariousstorageengines,eachsuitedfordifferentusecases:1)InnoDBisidealforapplicationsneedingACIDcomplianceandhighconcurrency,supportingtransactionsandforeignkeys.2)MyISAMisbestforread-heavyworkloads,lackingtransactionsupport.3)Memoryengineis

Common security vulnerabilities in MySQL include SQL injection, weak passwords, improper permission configuration, and unupdated software. 1. SQL injection can be prevented by using preprocessing statements. 2. Weak passwords can be avoided by forcibly using strong password strategies. 3. Improper permission configuration can be resolved through regular review and adjustment of user permissions. 4. Unupdated software can be patched by regularly checking and updating the MySQL version.

Identifying slow queries in MySQL can be achieved by enabling slow query logs and setting thresholds. 1. Enable slow query logs and set thresholds. 2. View and analyze slow query log files, and use tools such as mysqldumpslow or pt-query-digest for in-depth analysis. 3. Optimizing slow queries can be achieved through index optimization, query rewriting and avoiding the use of SELECT*.

To monitor the health and performance of MySQL servers, you should pay attention to system health, performance metrics and query execution. 1) Monitor system health: Use top, htop or SHOWGLOBALSTATUS commands to view CPU, memory, disk I/O and network activities. 2) Track performance indicators: monitor key indicators such as query number per second, average query time and cache hit rate. 3) Ensure query execution optimization: Enable slow query logs, record and optimize queries whose execution time exceeds the set threshold.

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

MySQL uses a GPL license. 1) The GPL license allows the free use, modification and distribution of MySQL, but the modified distribution must comply with GPL. 2) Commercial licenses can avoid public modifications and are suitable for commercial applications that require confidentiality.

The situations when choosing InnoDB instead of MyISAM include: 1) transaction support, 2) high concurrency environment, 3) high data consistency; conversely, the situation when choosing MyISAM includes: 1) mainly read operations, 2) no transaction support is required. InnoDB is suitable for applications that require high data consistency and transaction processing, such as e-commerce platforms, while MyISAM is suitable for read-intensive and transaction-free applications such as blog systems.

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools
