0

SQLiteサイトから、

ifnull() 関数は、2 つの引数を指定した coalesce() と同等です。

では、引数が 2 つある場合、どちらが速いでしょうか?

4

1 に答える 1

4

いくつかの実験でゴードン・リノフの発言を確認しました。セットアップ: Windows 8、i5 上の SQLiteSpy、および RAM 内のテーブル全体。

どちらのクエリも約 1.64 秒かかりましたが、変動は非常に小さく (0.1 秒未満) ありました。ほとんどの場合、1.64 秒で正確でした。

クエリ:

    create table t (
      a int, b int);

    insert into t values (null,null);
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;
    insert into t select case when random() < .5 then 1 end, case when random() < .5 then 1 end from t;

    select sum(ifnull(a, b)) from t;
    select sum(coalesce(a, b)) from t;
    select count(*) from t;
于 2013-07-24T02:52:46.483 に答える