SQLite資料庫怎麼這麼快?
才一個400多K的可執行檔案。做7個表笛卡爾積,共1千萬行,不到1秒。
sqlite> select count(*) from
...> (select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9 union select 10)a,
...> (select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9 union select 10)b,
...> (select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9 union select 10)c,
...> (select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9 union select 10)d,
...> (select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9 union select 10)e,
...> (select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9 union select 10)f,
...> (select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9 union select 10)g;
10000000
CPU Time: user 0.687500 sys 0.000000
如果count(*)可能用了取巧的辦法,再做加法的求和,應該沒什麼可取巧的了。這回用了5秒,但6個表的列相加,比起計數用時大幾倍可以理解。
sqlite> select sum(a.x+b.x+c.x+d.x+e.x+f.x) from
...> (select 1 x union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9
union select 10)a,
...> (select 1 x union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9
union select 10)b,
...> (select 1 x union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9
union select 10)c,
...> (select 1 x union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9
union select 10)d,
...> (select 1 x union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9
union select 10)e,
...> (select 1 x union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9
union select 10)f,
...> (select 1 x union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9
union select 10)g;
330000000
CPU Time: user 5.359375 sys 0.000000
把1百萬行查詢結果寫入物理表也很快,但建立索引比較慢。
sqlite> create table t1m (x int);
CPU Time: user 0.000000 sys 0.000000
sqlite> insert into t1m select a.x+b.x+c.x+d.x+e.x+f.x from
...> (select 1 x union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9
union select 10)a,
...> (select 1 x union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9
union select 10)b,
...> (select 1 x union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9
union select 10)c,
...> (select 1 x union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9
union select 10)d,
...> (select 1 x union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9
union select 10)e,
...> (select 1 x union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9
union select 10)f;
CPU Time: user 1.062500 sys 0.046875
sqlite> select count(*) from t1m;
1000000
CPU Time: user 0.015625 sys 0.015625
sqlite> create index t1m_x on t1m(x);
CPU Time: user 3.390625 sys 0.218750
sqlite> select count(*) from t1m where x=6;
1
CPU Time: user 0.000000 sys 0.015625
相關文章
- 資料庫批量插入這麼講究的麼?資料庫
- 資料庫怎麼分庫分表資料庫
- Redis為何這麼快–資料儲存角度Redis
- 為什麼NoSQL資料庫這麼受歡迎?SQL資料庫
- mysql資料庫怎麼連線MySql資料庫
- postgresql資料庫怎麼備份SQL資料庫
- Android之怎麼使用SQLite資料庫(增、刪、改、查、分頁等)以及ListView顯示資料AndroidSQLite資料庫View
- Jtti:sqlserver怎麼清空資料庫資料JttiSQLServer資料庫
- 資料怎麼插不進去(資料庫)?資料庫
- 為什麼會有這麼多種的資料庫資料庫
- Nginx 為什麼這麼快?Nginx
- Redis為什麼這麼快?Redis
- sqlite 資料庫的資料字典SQLite資料庫
- mongodb怎麼手動建立資料庫MongoDB資料庫
- 寶塔皮膚 資料庫怎麼連資料庫
- python怎麼連線資料庫Python資料庫
- Pycharm 怎麼連線 MySQL 資料庫PyCharmMySql資料庫
- Oracle資料庫該怎麼入門?Oracle資料庫
- mysql 的資料庫同步怎麼配置?MySql資料庫
- sqlserver資料庫埠號怎麼修改SQLServer資料庫
- sqlite操作--- oracle資料庫中的資料導進sqliteSQLiteOracle資料庫
- 汽車行業大資料分析怎麼做?快試試這個資料分析工具,小白也能做行業大資料
- 資料庫不能直連怎麼造資料呢資料庫
- 【Java】操作Sqlite資料庫JavaSQLite資料庫
- Redis 為何這麼快?聊聊它的資料結構~Redis資料結構
- SQLite資料庫管理器:SQLPro for SQLite for MacSQLite資料庫Mac
- 快速排序為什麼這麼快?排序
- 這樣的環境資料怎麼儲存?
- android sqlite資料庫 新增資料AndroidSQLite資料庫
- java怎麼將excel表格資料匯入資料庫JavaExcel資料庫
- mysql無法建立資料庫怎麼辦MySql資料庫
- 怎麼設定資料庫的報警資料庫
- 資料庫HTAP能力強弱怎麼看資料庫
- 資料庫Hang住怎麼辦 - HANGANALYZE資料庫
- 帝國cms資料庫怎麼恢復資料庫
- 怎麼建立網站連線資料庫網站資料庫
- 網站連線資料庫怎麼辦網站資料庫
- 網站資料庫密碼怎麼修改?網站資料庫密碼