Oracle 的 char number varchar2 效率测试
自己在建表的时候,用到了编号的这个字段,
主要问题是要用java连接数据库,所以要有pojo类,
就像 编号 这种字段,int 不够,long 转起来麻烦,还容易出错。
突然想看看char可不可以,所以就稀里糊涂的想看看,这几种数据类型的查找效率究竟如何。
--首先总要先建立一张表吧(如果有重复的话,先删掉...)
drop table yard_test;
create table yard_test (
yrd_id char(32),
yrd_num number,
yrd_var varchar2(32),
into_time date,
yrd_txt varchar2(4000)
);
--必然要有需要的数据类型 char number varchar2
--下面可以插入数据了,建一个plsql语句块,执行一下就可以。
declare
v_temp yard_test%rowtype;
v_begin_time timestamp := systimestamp;
v_end_time timestamp;
v_all_time timestamp;
begin
for i in 1..100 loop
--每一万条数据提交一次,总共提交100万次,其实有点多,我都没耐性等他插入完成就......
for j in 1..10000 loop
v_temp.yrd_id := sys_guid();
v_temp.yrd_var := sys_guid();
select nvl(max(yrd_num),0)+1 into v_temp.yrd_num from yard_test;
--本来应该用sequence的,嫌麻烦,,直接用select语句取得max值+1 得到了序号...
v_temp.yrd_txt := substr(sys_guid(),1,1);
insert into yard_test values(
v_temp.yrd_id,
v_temp.yrd_num,
v_temp.yrd_var,
systimestamp,
v_temp.yrd_txt);
v_end_time := systimestamp;
v_all_time := v_all_time + (v_end_time - v_begin_time);
--插入数据
end loop;
commit;
dbms_output.put_line(v_all_time);
end loop;
dbms_output.put_line(v_all_time);
end;
--好了,可以看看都插入了写什么数据,
select * from yard_test;
--下面开始测试
declare
v_beg timestamp;--一定要记好开始时间
v_end timestamp;--和结束时间
v_times number := 100000;
begin
--测试查找第50000条数据的速度
v_beg := systimestamp;
for i in 1..v_times loop
execute immediate 'select * from yard_test where yrd_num = 50000';
--用execute直接运行sql语句,这里是通过number查找数据
end loop;
v_end := systimestamp;
dbms_output.put_line('number 查询时间 ' || (v_end-v_beg));
v_beg := systimestamp;
for i in 1..v_times loop
execute immediate 'select * from yard_test where yrd_id = ''4A6585C231B64BD1B5A981EDD8079990''';
end loop;
v_end := systimestamp;
dbms_output.put_line('char 查询时间 ' || (v_end-v_beg));
v_beg := systimestamp;
for i in 1..v_times loop
execute immediate 'select * from yard_test where yrd_var = ''18C00CA4677E4BF388BD9F3891BBACA0''';
end loop;
v_end := systimestamp;
dbms_output.put_line('carchar2 查询时间 ' || (v_end-v_beg));
end;
其实在网上我也发现有其他同学做的测试,结论也都一样...
都是 char 效率最高,number 其次,最慢的是varchar2,差的也不大,也都能接受。

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc


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

SublimeText3 Mac version
God-level code editing software (SublimeText3)

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

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools
