Oracle PL/SQL 优化与调整 – PL/SQL Native Compilation 说明

2024-04-04 02:18

本文主要是介绍Oracle PL/SQL 优化与调整 – PL/SQL Native Compilation 说明,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

一.相关概述

在之前的Bulk的那篇blog里提到了Oracle 的2个引擎:PL/SQL 引擎和SQL 引擎。

Oracle PL/SQL 优化与调整 -- Bulk 说明

http://www.cndba.cn/Dave/article/1534

 

Oracle 使用2个引擎来执行SQL和代码块:SQL 引擎和PL/SQL 引擎, Oracle 使用这2个引擎来执行PL/SQL blocks 和 subprograms。那么在执行的时候,PL/SQL 引擎把DML 语句发送给SQL 引擎,然后由SQL 引擎执行,执行完毕后,SQL 引擎把结果集在发送给PL/SQL 引擎。因此在不同引擎之间切换就需要进行context switch,过多的context switch是会影响SQL性能的。而bulk 就是从减少引擎之间context switches的方式来提高sql的效率。 把对SQL 进行打包处理。 

 

这里看另一个处理角度,使用PL/SQLNative Compilation(PL/SQL的本地编译)。

 

官网的链接如下:

PL/SQL Native Compilation

http://docs.oracle.com/cd/E11882_01/server.112/e23633/changes.htm#UPGRD12523

 

Compiling PL/SQL Units for Native Execution

http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/tuning.htm

 

1.1 PL/SQL Native Compilation

Starting withOracle Database 10g Release 1 (10.1), the configuration of initializationparameters and the command setup for native compilation has been simplified.The important parameters now are PLSQL_NATIVE_LIBRARY_DIR and PLSQL_NATIVE_LIBRARY_SUBDIR_COUNT.

The parametersrelated to the compiler, linker, and make utility have been made obsolete.Native compilation is turned on and off by a separate initializationparameter, PLSQL_CODE_TYPE, rather than being one of several options inthe PLSQL_COMPILER_FLAGS parameter, which is now deprecated.The spnc_commands file, located in the ORACLE_HOME/plsqldirectory, contains the commands and options for compiling and linking, ratherthan a makefile.

       --在Oracle10g以后,配置native compilation 相对简单很多,最重要的参数是:PLSQL_NATIVE_LIBRARY_DIR 和 PLSQL_NATIVE_LIBRARY_SUBDIR_COUNT.

关联complier,linker 的参数已经过期。Native compilation 通过一个PLSQL_CODE_TYPE 参考来控制启动和关闭。 在10g 之前是使用PLSQL_COMPILER_FLAGS参数。

spnc_commands  文件存在ORACLE_HOME/plsql 目录下。如:

 

[oracle@rac1plsql]$ pwd

/u01/app/oracle/product/10.2.0/db_1/plsql

[oracle@rac1plsql]$ ls

admin  include lib  mesg  public spnc_commands

[oracle@rac1plsql]$ ll

total 24

drwxr-x--- 2oracle oinstall 4096 Mar 22  2011 admin

drwxr-x--- 2oracle oinstall 4096 Mar 22  2011 include

drwxr-x--- 2oracle oinstall 4096 May 12  2011 lib

drwxr-x--- 2oracle oinstall 4096 Mar 22  2011 mesg

drwxr-x--- 2oracle oinstall 4096 Mar 22  2011 public

-rw-r--r-- 1oracle oinstall 2065 Jun  3  2005 spnc_commands

 

       另一篇官网也提到了Oracle 10g 开始,PLSQL_COMPILER_FLAGS参数被标记为Obsolete, 该参数由 PLSQL_CODE_TYPE 和PLSQL_DEBUG参数代替。具体参考:

A Behavior Changes After Upgrading toOracle Database 11gR2

http://docs.oracle.com/cd/E11882_01/server.112/e23633/changes.htm#UPGRD12573

 

1.2 Compiling PL/SQL Units for Native Execution

You can usually speed up PL/SQL units bycompiling them into native code (processor-dependent system code), which isstored in the SYSTEM tablespace.

You can natively compile any PL/SQL unit ofany type, including those that Oracle Database supplies.

       可以将PL/SQL单元编译到native code里,这样可以提高PL/SQL的速度,编译后的PL/SQL单元存放在SYSTEM 表空间里。可以对任何PL/SQL unit 使用nativecompile。

 

Natively compiled program units work in all server environments, including shared serverconfiguration (formerly called "multithreaded server") and OracleReal Application Clusters (Oracle RAC).

--Natively compiled 程序单元在所有服务端运行,包括sharedserver 配置和RAC 环境。

On mostplatforms, PL/SQL native compilation requires no special set-up or maintenance.On some platforms, the DBA might want to do some optional configuration.

--在大多数平台下,PL/SQL native compilation 不需要特别的安装和维护,在少数平台下,DBA 可能需要做一些配置。

You can test tosee how much performance gain you can get by enabling PL/SQL nativecompilation.

--可以启动PL/SQL native compilation 测试对性能的提升。

 

If you havedetermined that PL/SQL native compilation will provide significant performancegains in database operations, Oracle recommends compiling the entire databasefor native mode, which requires DBA privileges. This speeds up both your owncode and calls to the PL/SQL packages that Oracle Database supplies.

--如果提升较大,Oracle 建议使用native mode,这个需要DBA权限。

 

Topics

(1)    DeterminingWhether to Use PL/SQL Native Compilation

(2)    HowPL/SQL Native Compilation Works

(3)    Dependencies,Invalidation, and Revalidation

(4)    SettingUp a New Database for PL/SQL Native Compilation*

(5)    Compilingthe Entire Database for PL/SQL Native or Interpreted Compilation*

* Requires DBA privileges.

 

1.2.1 DeterminingWhether to Use PL/SQL Native Compilation

       --决定是否使用PL/SQL Native Compilation

Whether tocompile a PL/SQL unit for native or interpreted mode depends on where you arein the development cycle and on what the program unit does.

       --使用native 或者 interpreted 模式决定于开发周期和程序单元。

While you aredebugging program units and recompiling them frequently, interpreted mode hasthese advantages:

--如果是debug 程序单元,且经常recompiling,那么使用interpreted模式有如下好处:

(1)You can usePL/SQL debugging tools on program units compiled for interpreted mode (but notfor those compiled for native mode).

(2)Compiling forinterpreted mode is faster than compiling for native mode.

 

After thedebugging phase of development, in determining whether to compile a PL/SQL unitfor native mode, consider:

--除了上面提到的development 模式,是否使用native 模式,还需要考虑如下因素:

(1)PL/SQL nativecompilation provides the greatest performance gains for computation-intensiveprocedural operations. Examples are data warehouse applications andapplications with extensive server-side transformations of data for display.

(2)PL/SQL nativecompilation provides the least performance gains for PL/SQL subprograms thatspend most of their time running SQL.

(3)When manyprogram units (typically over 15,000) are compiled for native execution, andare simultaneously active, the large amount of shared memory required mightaffect system performance.

--当很多program units已native execution 编译,当他们同时执行时,就会消耗大量的shared 内存,从而影响系统性能。

 

1.2.2 How PL/SQLNative Compilation Works

Without nativecompilation, the PL/SQL statements in a PL/SQL unit are compiled into anintermediate form, system code, which is stored in the catalog and interpretedat run time.

       --没有使用native compilation时,PL/SQL 单元里的PL/SQL语句会被编译成中间码,系统码(机器可读的形式),其存储在catalog里并在运行时被解释。

 

With PL/SQLnative compilation, the PL/SQL statements in a PL/SQL unit are compiled intonative code and stored in the catalog. The native code need not be interpretedat run time, so it runs faster.

--如果使用native compilation,那么PL/SQL 单元里的PL/SQL语句就会使用被编译成native code(C代码),然后存储在catalog里。 Native code 在运行时不需要进行解释,所以运行很快,性能会得到提升。

 

Because nativecompilation applies only to PL/SQL statements, a PL/SQL unit that uses only SQLstatements might not run faster when natively compiled, but it does run atleast as fast as the corresponding interpreted code. The compiled code and theinterpreted code make the same library calls, so their action is the same.

--Native compilation 仅使用于PL/SQL 语句,所以一个PL/SQL单元在使用natively compiled 时可能并不会块多少,但是至少大于等于使用interpretedcode。

Compiled code 和 interpreted code 使用相同的的library calls,所以他们的行为是相同的。

 

The first time anatively compiled PL/SQL unit runs, it is fetched from the SYSTEM tablespaceinto shared memory. Regardless of how many sessions invoke the program unit,shared memory has only one copy it. If a program unit is not being used, theshared memory it is using might be freed, to reduce memory load.

--当用natively compiled PL/SQL 单元第一次运行时,其会从SYSTEM 表空间里抽取到shared memory里。不管多有sessions 调用这个程序单元,shared memory 只有一份copy。 如果程序单元没有使用,那么其可能会从shared memory中释放表,以节省内存空间。

 

Nativelycompiled subprograms and interpreted subprograms can invoke each other.

       --Natively compiled 子程序和 interpreted 子程序之间可以相互调用。

 

PL/SQL nativecompilation works transparently in an Oracle Real Application Clusters (OracleRAC) environment.

 

The PLSQL_CODE_TYPE compilationparameter determines whether PL/SQL code is natively compiled or interpreted.

-- PLSQL_CODE_TYPE 参数控制PL/SQL 的模式是nativelycompiled 还是interpreted。

 

1.2.3 Dependencies,Invalidation, and Revalidation

Recompilation isautomatic with invalidated PL/SQL modules. For example, if an object on which anatively compiled PL/SQL subprogram depends changes, the subprogram isinvalidated. The next time the same subprogram is called, the databaserecompiles the subprogram automatically. Becausethe PLSQL_CODE_TYPE setting is stored inside the library unit foreach subprogram, the automatic recompilation uses this stored setting for codetype.

       --当一个PL/SQL 模块失效后会自动进行recompilation。PLSQL_CODE_TYPE的值保存在library unit里,自动recompilation 会使用这个参数值。

 

Explicitrecompilation does not necessarily use thestored PLSQL_CODE_TYPE setting.

显示的recompilation 不需要使用 PLSQL_CODE_TYPE设置。

 

For the conditions under which explicit recompilation uses stored settings, see "PL/SQLUnits and Compilation Parameters".

 

1.2.4 Setting Up aNew Database for PL/SQL Native Compilation

If you have DBAprivileges, you can set up a new database for PL/SQL native compilation bysetting the compilation parameter PLSQL_CODE_TYPE to NATIVE. Theperformance benefits apply to the PL/SQL packages that Oracle Databasesupplies, which are used for many database operations.

       --如果是一个新的实例,并且有DBA的权限,可以设置PLSQL_CODE_TYPE为NATIVE来启用Nativecompilation。

 

Note:

If you compilethe whole database as NATIVE, Oracle recommends that youset PLSQL_CODE_TYPE at the system level.

       --如果在整个数据库都设置为native,那么建议在系统级别进行设置。

 

1.2.5 Compilingthe Entire Database for PL/SQL Native or Interpreted Compilation

If you have DBAprivileges, you can recompile all PL/SQL modules in an existing databaseto NATIVE or INTERPRETED, using the dbmsupgnv.sql and dbmsupgin.sql scripts respectively during the processexplained in this section. Before making the conversion, review "DeterminingWhether to Use PL/SQL Native Compilation".

--如果是对已经创建好的DB修改模式到Native 或者 interpreted,那么需要使用dbmsupgnv.sql和 dbmsupgin.sql脚本。

 

During theconversion to native compilation, TYPE specifications are notrecompiled by dbmsupgnv.sql to NATIVE because thesespecifications do not contain executable code.

--转到到native compilation时,dbmsupgnv.sql 不会recompiledTYPE specifications到Native 模式,因为这个specifications 不包含执行代码。

 

Packagespecifications seldom contain executable code so the run-time benefits ofcompiling to NATIVE are not measurable. You can usethe TRUE command-line parameter withthe dbmsupgnv.sql script to exclude package specs from recompilationto NATIVE, saving time in the conversion process.

--Package specifications 很少包含执行代码,所以编译到Native的效率不能估量。 可以在命令行执行dbmsupgnv.sql 脚本,从而排除recompilationpackage specs到native,节省转换的时间。

 

When convertingto interpreted compilation, the dbmsupgin.sql script does not acceptany parameters and does not exclude any PL/SQL units.

--转换到interpreted compilation时,dbmsupgin.sql 脚本不接收任何参数也不排除任何PL/SQL 单元。

 

Note:

The followingprocedure describes the conversion to native compilation. If you must recompileall PL/SQL modules to interpretedcompilation, make these changes in the steps.

--以下过程描述了转换到native compilation, 如果必须将所有的PL/SQL 模块转换到interpretedcomplilation,那么在转换到native 的基础上改变如下3个步骤即可。

(1)    Skip the first step.

(2)    Setthe PLSQL_CODE_TYPE compilation parameterto INTERPRETED rather than NATIVE.

(3)    Substitute dbmsupgin.sql forthe dbmsupgnv.sql script.

 

 

1.Ensure that a test PL/SQL unit can becompiled. For example:

ALTER PROCEDUREmy_proc COMPILE PLSQL_CODE_TYPE=NATIVE REUSE SETTINGS;

 

2.Shut down application services, thelistener, and the database.

(1)Shut down allof the Application services including the Forms Processes, Web Servers, ReportsServers, and Concurrent Manager Servers. After shutting down all of theApplication services, ensure that all of the connections to the database wereterminated.

(2)Shut down theTNS listener of the database to ensure that no new connections are made.

(3)Shut down thedatabase in normal or immediate mode as the user SYS. Se

 

3.Set PLSQL_CODE_TYPE to NATIVE inthe compilation parameter file. If the database is using a server parameterfile, then set this after the database has started.

The valueof PLSQL_CODE_TYPE does not affect the conversion of the PL/SQL unitsin these steps. However, it does affect all subsequently compiled units, soexplicitly set it to the desired compilation type.

 

4.Start up the database in upgrade mode,using the UPGRADE option. For information aboutSQL*Plus STARTUP, see SQL*PlusUser's Guide and Reference.

 

5.Run this code to list the invalid PL/SQLunits. You can save the output of the query for future reference with the SQL SPOOL statement:

-- To save the output of the query to afile:

 SPOOL pre_update_invalid.log

SELECT o.OWNER, o.OBJECT_NAME,o.OBJECT_TYPE

FROM DBA_OBJECTS o,DBA_PLSQL_OBJECT_SETTINGS s

WHERE o.OBJECT_NAME = s.NAME ANDo.STATUS='INVALID';

--查看无效的PL/SQL单元

 

-- To stop spooling the output: SPOOL OFF

If any Oracle supplied units are invalid,try to validate them by recompiling them. For example:

ALTER PACKAGE SYS.DBMS_OUTPUT COMPILE BODYREUSE SETTINGS;

--编译无效的单元。

 

If the units cannot be validated, save thespooled log for future resolution and continue.

 

6.Run this query todetermine how many objects arecompiled NATIVE and INTERPRETED (to save the output, usethe SQL SPOOL statement):

SELECT TYPE, PLSQL_CODE_TYPE, COUNT(*)

FROM DBA_PLSQL_OBJECT_SETTINGS

WHERE PLSQL_CODE_TYPE IS NOT NULL

GROUP BY TYPE, PLSQL_CODE_TYPE

ORDER BY TYPE, PLSQL_CODE_TYPE;

 

Any objects witha NULL plsql_code_type are special internal objects and can beignored.


7.Runthe $ORACLE_HOME/rdbms/admin/dbmsupgnv.sql script as the user SYS toupdate the plsql_code_type setting to NATIVE in thedictionary tables for all PL/SQL units. This process also invalidates theunits. Use TRUE with the script to exclude packagespecifications; FALSE to include the package specifications.

This update mustbe done when the database is in UPGRADE mode. The script isguaranteed to complete successfully or rollback all the changes.

--在UPGRADE 模式下使用SYS用户来执行 $ORACLE_HOME/rdbms/admin/dbmsupgnv.sql 脚本,更新plsql_code_type设置到数据字典表。

 

8.Shut down the database and restartin NORMAL mode.

 

9.Before you runthe utlrp.sql script, Oracle recommends that no other sessions areconnected to avoid possible problems. You can ensure this with this statement:

ALTER SYSTEMENABLE RESTRICTED SESSION;

 

10.Run the $ORACLE_HOME/rdbms/admin/utlrp.sql scriptas the user SYS. This script recompiles all the PL/SQL modules using adefault degree of parallelism. See the comments in the script for informationabout setting the degree explicitly.

If for anyreason the script is abnormally terminated, rerunthe utlrp.sql script to recompile any remaining invalid PL/SQLmodules.

 

11.After the compilation completessuccessfully, verify that there are no invalid PL/SQL units using the query instep 5.You can spool the output of the query tothe post_upgrade_invalid.log file and compare the contents withthe pre_upgrade_invalid.log file, if it was created previously.

 

12.Reexecute the query in step 6.If recompiling with dbmsupgnv.sql, confirm that all PL/SQL units,except TYPE specifications and package specifications if excluded,are NATIVE. If recompiling withdbmsupgin.sql, confirm that all PL/SQLunits are INTERPRETED.

 

13.Disable the restricted session mode forthe database, then start the services that you previously shut down. To disablerestricted session mode, use this statement:

ALTER SYSTEMDISABLE RESTRICTED SESSION;

 

 

二.相关参数说明

 

SQL> select * from v$version;

 

BANNER

----------------------------------------------------------------

Oracle Database 10g Enterprise EditionRelease 10.2.0.4.0 - Prod

PL/SQL Release 10.2.0.4.0 - Production

CORE    10.2.0.4.0      Production

TNS for Linux: Version 10.2.0.4.0 -Production

NLSRTL Version 10.2.0.4.0 - Production

 

SQL> show parameter plsql

NAME                                 TYPE        VALUE

----------------------------------------------- ------------------------------

plsql_ccflags                        string

plsql_code_type                      string      INTERPRETED

plsql_compiler_flags                 string      INTERPRETED, NON_DEBUG

plsql_debug                          boolean     FALSE

plsql_native_library_dir             string

plsql_native_library_subdir_count    integer    0

plsql_optimize_level                 integer     2

plsql_v2_compatibility               boolean     FALSE

plsql_warnings                       string      DISABLE:ALL

 

PLSQL_NATIVE_LIBRARY_DIR and PLSQL_NATIVE_LIBRARY_SUBDIR_COUNT.

The parameters related to the compiler,linker, and make utility have been made obsolete. Native compilation is turnedon and off by a separate initialization parameter, PLSQL_CODE_TYPE,

 

2.1 PLSQL_OPTIMIZE_LEVEL

http://docs.oracle.com/cd/E11882_01/server.112/e25513/initparams194.htm#REFRN10255

 

Property

Description

Parameter type

Integer

Default value

2

Modifiable

ALTER SESSION, ALTER SYSTEM

Range of values

0 to 3

 

PLSQL_OPTIMIZE_LEVEL specifiesthe optimization level that will be used to compile PL/SQL library units. Thehigher the setting of this parameter, the more effort the compiler makes tooptimize PL/SQL library units.

       -- PLSQL_OPTIMIZE_LEVEL 指定optimization 的级别,其值越高,compiler 的性能也越优化。 在Oracle 10g中该参数只能从0到2,在Oracle11g里,增加了3. 默认值2.

 

Values:

(1)0

Maintains theevaluation order and hence the pattern of side effects, exceptions, and packageinitializations of Oracle9i and earlier releases. Also removes the newsemantic identity of BINARY_INTEGER and PLS_INTEGER and restoresthe earlier rules for the evaluation of integer expressions. Although code willrun somewhat faster than it did in Oracle9i, use of level 0 will forfeit mostof the performance gains of PL/SQL in Oracle Database 10g.

(2)1

Applies a widerange of optimizations to PL/SQL programs including the elimination ofunnecessary computations and exceptions, but generally does not move sourcecode out of its original source order.

(3)2

Applies a widerange of modern optimization techniques beyond those of level 1 includingchanges which may move source code relatively far from its original location.

(3)3

Applies a widerange of optimization techniques beyond those of level 2, automaticallyincluding techniques not specifically requested.

 

Generally,setting this parameter to 2 pays off in better execution performance.If, however, the compiler runs slowly on a particular source module or ifoptimization does not make sense for some reason (for example, during rapidturnaround development), then setting this parameter to 1 will resultin almost as good a compilation with less use of compile-time resources.

The value ofthis parameter is stored persistently with the library unit.

 

2.2 PLSQL_CODE_TYPE

http://docs.oracle.com/cd/E11882_01/server.112/e25513/initparams192.htm#REFRN10253

 

Property

Description

Parameter type

String

Syntax

PLSQL_CODE_TYPE = { INTERPRETED | NATIVE }

Default value

INTERPRETED

Modifiable

ALTER SESSION, ALTER SYSTEM

 

PLSQL_CODE_TYPE specifies thecompilation mode for PL/SQL library units.

--该参数指定compilation模型。有如下值:

Values:

(1)INTERPRETED

PL/SQL libraryunits will be compiled to PL/SQL by tecode format. Such modules are executed bythe PL/SQL interpreter engine.

--声明PL/SQL库单元被编译成PL/SQL字节码格式,这些模块由PL/SQL解释引擎执行;

 

(2)NATIVE

PL/SQL libraryunits (with the possible exception of top-level anonymous PL/SQL blocks) willbe compiled to native (machine) code. Such modules will be executed nativelywithout incurring any interpreter overhead.

       -- PL/SQL库单元被编译成本地机器码;

 

When the valueof this parameter is changed, it has no effect on PL/SQL library units thathave already been compiled. The value of this parameter is stored persistentlywith each library unit.

--修改该参数不影响已经compiled 的units。

If a PL/SQLlibrary unit is compiled native, all subsequent automatic recompilations ofthat library unit will use native compilation.

 

 

2.3 PLSQL_CCFLAGS

http://docs.oracle.com/cd/E11882_01/server.112/e25513/initparams191.htm#REFRN10261

 

Property

Description

Parameter type

String

Syntax

PLSQL_CCFLAGS = '<v1>:<c1>,<v2>:<c2>,...,<vn>:<cn>'

Default value

Empty string

Modifiable

ALTER SESSION, ALTER SYSTEM

Range of values

Any string literal that satisfies the internal syntax

Examples

ALTER SESSION SET PLSQL_CCFLAGS = 'DeBug:TruE';

ALTER SESSION SET PLSQL_CCFLAGS = 'debug:TRUE';

 

PLSQL_CCFLAGS providesa mechanism that allows PL/SQL programmers to control conditional compilationof each PL/SQL library unit independently.

--PLSQL_CCFLAGS提供一个机制允许PL/SQL 程序控制每个PL/SQL library 单元独立编译的条件。 有如下值:

 

Values:

(1)<vi>has the form of an unquoted PL/SQL identifier. It is unrestricted and can be areserved word or a keyword. The text is insensitive to case. Each one is knownas a flag or flag name. Each <vi> can occur more than once in the string,each occurrence can have a different flag value, and the flag values can be ofdifferent kinds.

(2)<ci> isone of the following: a PL/SQL boolean literal, a PLS_INTEGER literal,or the literal NULL. The text is insensitive to case. Each one is known as aflag value and corresponds to a flag name.

 

You can defineany allowable value for PLSQL_CCFLAGS. However, Oracle recommends thatthis parameter be used for controlling the conditional compilation of debuggingor tracing code. It is recommended that the following identifiers not be usedas flag name values:

(1)Names ofOracle parameters (for example, NLS_LENGTH_SEMANTICS)

(2)Identifierswith any of the following prefixes: PLS_, PLSQL_, PLSCC_, ORA_, ORACLE_, DBMS_, SYS_

 

 

 

 

 

 

 

-------------------------------------------------------------------------------------------------------

版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!

QQ:492913789

Email:ahdba@qq.com

Blog:  http://www.cndba.cn/dave

Weibo:    http://weibo.com/tianlesoftware

Twitter:  http://twitter.com/tianlesoftware

Facebook: http://www.facebook.com/tianlesoftware

Linkedin: http://cn.linkedin.com/in/tianlesoftware

 

-------加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请----

DBA1 群:62697716(满);   DBA2 群:62697977(满)  DBA3 群:62697850(满)  

DBA 超级群:63306533(满);  DBA4 群:83829929   DBA5群: 142216823

DBA6 群:158654907    DBA7 群:172855474  

这篇关于Oracle PL/SQL 优化与调整 – PL/SQL Native Compilation 说明的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/874564

相关文章

Vue3 的 shallowRef 和 shallowReactive:优化性能

大家对 Vue3 的 ref 和 reactive 都很熟悉,那么对 shallowRef 和 shallowReactive 是否了解呢? 在编程和数据结构中,“shallow”(浅层)通常指对数据结构的最外层进行操作,而不递归地处理其内部或嵌套的数据。这种处理方式关注的是数据结构的第一层属性或元素,而忽略更深层次的嵌套内容。 1. 浅层与深层的对比 1.1 浅层(Shallow) 定义

SQL中的外键约束

外键约束用于表示两张表中的指标连接关系。外键约束的作用主要有以下三点: 1.确保子表中的某个字段(外键)只能引用父表中的有效记录2.主表中的列被删除时,子表中的关联列也会被删除3.主表中的列更新时,子表中的关联元素也会被更新 子表中的元素指向主表 以下是一个外键约束的实例展示

基于MySQL Binlog的Elasticsearch数据同步实践

一、为什么要做 随着马蜂窝的逐渐发展,我们的业务数据越来越多,单纯使用 MySQL 已经不能满足我们的数据查询需求,例如对于商品、订单等数据的多维度检索。 使用 Elasticsearch 存储业务数据可以很好的解决我们业务中的搜索需求。而数据进行异构存储后,随之而来的就是数据同步的问题。 二、现有方法及问题 对于数据同步,我们目前的解决方案是建立数据中间表。把需要检索的业务数据,统一放到一张M

Zookeeper安装和配置说明

一、Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及伪集群模式。 ■ 单机模式:Zookeeper只运行在一台服务器上,适合测试环境; ■ 伪集群模式:就是在一台物理机上运行多个Zookeeper 实例; ■ 集群模式:Zookeeper运行于一个集群上,适合生产环境,这个计算机集群被称为一个“集合体”(ensemble) Zookeeper通过复制来实现

如何去写一手好SQL

MySQL性能 最大数据量 抛开数据量和并发数,谈性能都是耍流氓。MySQL没有限制单表最大记录数,它取决于操作系统对文件大小的限制。 《阿里巴巴Java开发手册》提出单表行数超过500万行或者单表容量超过2GB,才推荐分库分表。性能由综合因素决定,抛开业务复杂度,影响程度依次是硬件配置、MySQL配置、数据表设计、索引优化。500万这个值仅供参考,并非铁律。 博主曾经操作过超过4亿行数据

HDFS—存储优化(纠删码)

纠删码原理 HDFS 默认情况下,一个文件有3个副本,这样提高了数据的可靠性,但也带来了2倍的冗余开销。 Hadoop3.x 引入了纠删码,采用计算的方式,可以节省约50%左右的存储空间。 此种方式节约了空间,但是会增加 cpu 的计算。 纠删码策略是给具体一个路径设置。所有往此路径下存储的文件,都会执行此策略。 默认只开启对 RS-6-3-1024k

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

MySQL数据库宕机,启动不起来,教你一招搞定!

作者介绍:老苏,10余年DBA工作运维经验,擅长Oracle、MySQL、PG、Mongodb数据库运维(如安装迁移,性能优化、故障应急处理等)公众号:老苏畅谈运维欢迎关注本人公众号,更多精彩与您分享。 MySQL数据库宕机,数据页损坏问题,启动不起来,该如何排查和解决,本文将为你说明具体的排查过程。 查看MySQL error日志 查看 MySQL error日志,排查哪个表(表空间

MySQL高性能优化规范

前言:      笔者最近上班途中突然想丰富下自己的数据库优化技能。于是在查阅了多篇文章后,总结出了这篇! 数据库命令规范 所有数据库对象名称必须使用小写字母并用下划线分割 所有数据库对象名称禁止使用mysql保留关键字(如果表名中包含关键字查询时,需要将其用单引号括起来) 数据库对象的命名要能做到见名识意,并且最后不要超过32个字符 临时库表必须以tmp_为前缀并以日期为后缀,备份