简体   繁体   English

为什么Oracle插入比Mysql快

[英]Why Oracle insert faster than Mysql

I have a little compharison between oracle 11gR2 and Mysql 5.6.我对 oracle 11gR2 和 Mysql 5.6 有一些比较。

I create same schema in both DBMS with 3 tables --branch --client --loan loan has a foreign key to client, and a client has a foreign key to branch, besides all of them have primary keys.我在具有 3 个表的两个 DBMS 中创建了相同的模式 --branch --client --loan 贷款有一个到客户的外键,一个客户有一个到分支的外键,此外它们都有主键。

I created branches, and client (200_000 clients) and I wanna tests insert perfomance with loan table which is consist around 50 columns.我创建了分支机构和客户(200_000 个客户),并且我想使用由大约 50 列组成的贷款表来测试插入性能。

Most of clolumns double or integer or string.大多数clolumns 双精度或整数或字符串。

create or replace PROCEDURE create_loans( n number)
as
BEGIN
    Declare 
    i number:=0;
    randDouble float ;
    randInt number;
    randString varchar2(50);
    Begin
      while i < n 
      Loop
         randDouble := ROUND(dbms_random.value(0,1),17);
         randInt := ROUND(dbms_random.value(1,100000000));
        randString := dbms_random.string('l', 50); 

        Insert into loan_row_model.loan values(null,
            randDouble,
            randDouble*10,
            randDouble*13,
            SUBSTR(randString,1,32),
            SUBSTR(randString,2,10),
            randDouble*155,
            SUBSTR(randString,1,9),
            SUBSTR(randString,9,10),
            SUBSTR(randString,1,32),
            randDouble*6123,--annual_inc
            SUBSTR(randString,3,32),--verification_status
            SUBSTR(randString,4,30),
            randDouble,
            randInt,--open_acc
            randInt*2,
            SUBSTR(randString,7,7),
        randInt*5,--total_acc
        SUBSTR(randString,1,3),--initial_list_status
            randDouble*64,
        randDouble*4,
        randDouble*231,
        randDouble,
        randDouble,
            randDouble*12,
            randDouble,--collection_recovery_fee
            SUBSTR(randString,19,30),
            randDouble*14,--last_pymnt_amnt
            SUBSTR(randString,21,32),
            SUBSTR(randString,9,30),
            SUBSTR(randString,16,15),--policy_code
            SUBSTR(randString,1,29),--application_type
            randInt,
            randInt*7,
            randInt*4,
            randInt,
            randInt,
            randInt,
            randInt*3,
            randInt,--mths_since_rcnt_il
            randDouble*6149,
            randInt*8,--open_rv_12m
            randInt*8,--open_rv_24m
            randDouble*475,
            randDouble*37,--all_util
            randInt*4,
            randInt,
            randInt*3,
            randInt,
            randInt*9,
            TO_DATE( TRUNC( DBMS_RANDOM.VALUE(TO_CHAR(DATE '2016-01-01','J'),TO_CHAR(DATE '2046-12-31','J') )),'J'),
            ROUND(dbms_random.value(1,200000))
            );
         i := i+1;
        end loop;
    end;
END;

the procedure in mysql almost identical, I just used their native random generator for values. mysql 中的过程几乎相同,我只是使用他们的原生随机生成器来获取值。

Before start I have disabled parallel executing in oracle, and flush cache, in mysql also disable cache.在开始之前,我在 oracle 中禁用了并行执行,并刷新了缓存,在 mysql 中也禁用了缓存。

But as a result for 50000 inserts Oracle has 15s vs 30s in Mysql.但结果是,对于 50000 次插入,Oracle 在 Mysql 中有 15 秒与 30 秒。

What is the reason, could you help?请问是什么原因,能帮帮忙吗?

MySQL can do that in 3 seconds if you "batch" 100 rows at a time.如果您一次“批处理”100 行,MySQL 可以在 3 秒内完成。 Perhaps even faster with LOAD DATA .使用LOAD DATA可能更快。

How often do you need to insert 50K rows?您多久需要插入 50K 行? In other words, why does it matter?换句话说,为什么重要?

Show us SHOW CREATE TABLE ;向我们SHOW CREATE TABLE ; there could be various issues (favorable or unfavorable) with the indexes or lack of them, and also in the datatypes, and especially the "engine".索引或缺少索引以及数据类型,尤其是“引擎”可能存在各种问题(有利或不利)。

Were they "finished"?他们“完成”了吗? Both Oracle and MySQL do some variant on "delayed writes" to avoid making you wait. Oracle 和 MySQL 都对“延迟写入”做了一些变体,以避免让您等待。 15s or 30s may or may not be sustainable. 15s 或 30s 可能会或可能不会持续。

Were you using spinning drives or SSDs?您使用的是旋转驱动器还是 SSD? RAID with write cache?带写缓存的 RAID? What about the settings for autocommit versus BEGIN...COMMIT?自动提交与 BEGIN...COMMIT 的设置如何? Did you even do a commit?你甚至做了一个承诺? Or does the timing include a rollback?!还是时间包括回滚?! Committing after each INSERT is not a good idea since it has a huge overhead.在每个INSERT之后提交并不是一个好主意,因为它有巨大的开销。

Were the settings tuned optimally?设置是否优化?

Did the table already have data?该表是否已有数据? Were you inserting "at the end"?你是在“最后”插入吗? Or randomly?还是随机的?

When you have answered all of those, I may have another 10 questions that will show that further things can be done to make your benchmark 'prove' that one vendor or the other is faster.当您回答完所有这些问题后,我可能还有另外 10 个问题,这些问题将表明可以做进一步的事情来使您的基准“证明”一个供应商另一个供应商更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM