課程實踐(一)續1
案例二
結論:在WHERE條件中不要在索引列上進行計算和使用函式
點選(此處)摺疊或開啟
-
--建立setup_rest.sh指令碼
-
# setup_rest.sh
-
# !/bin/bash
-
cd $HOME/solutions/Common_Mistakes
-
sqlplus / as sysdba <<EOF
-
-
SET ECHO ON
-
DROP USER jfv CASCADE;
-
CREATE USER jfv IDENTIFIED BY jfv DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp;
-
GRANT CONNECT, RESOURCE, DBA TO jfv;
-
CONN jfv/jfv
-
-
DROP TABLE orders PURGE;
-
CREATE TABLE orders
-
(
-
order_id_char VARCHAR2(50) PRIMARY KEY,
-
order_total_number NUMBER,
-
customer_name VARCHAR2(300)
-
);
-
-
BEGIN
-
FOR i IN 1..500000 LOOP
-
INSERT INTO orders VALUES
-
(i, 100, \'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-
aaaaaaaaaaaaaaaaaa\');
-
END LOOP;
-
COMMIT;
-
END;
-
/
-
-
BEGIN
-
FOR i IN 1..500000 LOOP
-
INSERT INTO orders VALUES
-
(500000 + i, 100, \'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-
aaaaaaaaaaaaaaaaaa\');
-
END LOOP;
-
COMMIT;
-
END;
-
/
-
-
DROP TABLE employees PURGE;
-
DROP TABLE job_history PURGE;
-
CREATE TABLE employees
-
(
-
employee_id NUMBER PRIMARY KEY,
-
NAME VARCHAR2(500)
-
);
-
BEGIN
-
FOR i IN 1..500000 LOOP
-
INSERT INTO employees VALUES
-
(i, \'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-
aaaaaaaaaaaaaaaaaa\');
-
END LOOP;
-
COMMIT;
-
END;
-
/
-
-
CREATE TABLE job_history
-
(
-
employee_id NUMBER,
-
job VARCHAR2(500)
-
);
-
BEGIN
-
FOR i IN 1..500000 LOOP
-
INSERT INTO job_history VALUES
-
(MOD(i, 1000), \'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-
aaaaaaaaaaaaaaaaaa\');
-
END LOOP;
-
COMMIT;
-
END;
-
/
-
CREATE INDEX idx_job_history_empid ON job_history(employee_id);
-
-
DROP TABLE OLD PURGE;
-
DROP TABLE NEW PURGE;
-
CREATE TABLE OLD
-
(
-
NAME VARCHAR2(10),
-
other VARCHAR2(500)
-
);
-
-
CREATE TABLE NEW
-
(
-
NAME VARCHAR2(10),
-
other VARCHAR2(500)
-
);
-
-
BEGIN
-
FOR i IN 1..500000 LOOP
-
INSERT INTO OLD
-
VALUES(i, \'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-
aaaaaaaaaaaaaaaaaa\');
-
END LOOP;
-
COMMIT;
-
END;
-
/
-
-
BEGIN
-
FOR i IN 1..500000 LOOP
-
INSERT INTO NEW
-
VALUES(i + 500000, \'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-
aaaaaaaaaaaaaaaaaa\');
-
END LOOP;
-
COMMIT;
-
END;
-
/
-
EOF
-
--執行setup_rest.sh指令碼建立環境, 以jfv使用者進入SQL*Plus
-
--2.1 bad
-
select count(*) from job_history jh, employees e
-
where substr(to_char(e.employee_id), 1) = substr(to_char(jh.employee_id), 1);
-
-
COUNT(*)
-
----------
-
499500
-
-
Elapsed: 00:00:08.19
-
-
--2.2 good
-
select count(*) from job_history jh, employees e where e.employee_id = jh.employee_id;
-
-
COUNT(*)
-
----------
-
499500
-
- Elapsed: 00:00:02.40
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17013648/viewspace-1072399/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 課程實踐(一)續
- 課程實踐(二)續
- 課程實踐(一)
- 課程實踐(二)
- 實踐JavaWeb課程專案JavaWeb
- 作業系統課程實踐報告作業系統
- [Triton課程筆記] 2.2.3 BLS續筆記
- (續)Css in js 一次實踐CSSJS
- 持續交付體系在高德的實踐歷程
- 課程 1: JSON 解析JSON
- 一個Web 持續整合工作實踐Web
- 機器學習業務實踐之路-李博-專題視訊課程機器學習
- spark sql 實踐(續)SparkSQL
- C++初步探索課程1之第一個程式C++
- Practice - iOS 專案持續整合實踐(一)iOS
- Practice – iOS 專案持續整合實踐(一)iOS
- 軟體工程的實踐專案課程的自我目標軟體工程
- Docker實踐過程中遇到的一些問題總結(持續更新中)Docker
- DevOps企業實踐和價值-CSDN公開課-專題視訊課程dev
- 企業級實戰大資料課程(一)-尹成-專題視訊課程大資料
- 第2周專案-課後實踐·閱讀程式(1)
- 微軟 Azure 動手實驗營-1月課程預告微軟
- python暑期課程 day1Python
- 第一章:Linux基礎實踐-CSDN就業班-專題視訊課程Linux就業
- 課程報名丨“重大活動”網路安全保障中的攻守實踐
- 持續整合領域的智慧排程探索及實踐 - 黃佳鑫
- 微軟線上技術公開課-1月課程預告微軟
- 遨遊Unix–APUE課程筆記【1】筆記
- 尚觀課程-1.Shell基礎
- Flutter web 持續整合實踐FlutterWeb
- Redis Cluster深入與實踐(續)Redis
- 持續整合(三):最佳實踐
- 我的慕課實戰課程上線了
- 省級一流課程
- 敏捷建模對統一過程的改造實踐敏捷
- 武漢專場|第二期《資料安全實踐專題培訓》課程即將開課
- 計算機實驗室之樹莓派:課程 1 OK01計算機樹莓派
- CI/CD 持續整合部署實踐