最近忙著把公司的數據庫從mysql遷移到oracle
環境
Linux version
Mem:
Swap:
CPU:兩個超線程的Intel(R) Xeon(TM) CPU
優化前語句在mysql裡面查詢
翻頁語句
SELECT * FROM (SELECT T
SELECT /*+ index(a ind_old)*/
a
被查詢的表
表結構
Code: [Copy to clipboard]
SQL> desc auction_auctions;
Name Null? Type
ID NOT NULL VARCHAR
USERNAME VARCHAR
TITLE CLOB
GMT_MODIFIED NOT NULL DATE
STARTS NOT NULL DATE
DESCRIPTION CLOB
PICT_URL CLOB
CATEGORY NOT NULL VARCHAR
MINIMUM_BID NUMBER
RESERVE_PRICE NUMBER
BUY_NOW NUMBER
AUCTION_TYPE CHAR(
DURATION VARCHAR
INCREMENTNUM NOT NULL NUMBER
CITY VARCHAR
PROV VARCHAR
LOCATION VARCHAR
LOCATION_ZIP VARCHAR
SHIPPING CHAR(
PAYMENT CLOB
INTERNATIONAL CHAR(
ENDS NOT NULL DATE
CURRENT_BID NUMBER
CLOSED CHAR(
PHOTO_UPLOADED CHAR(
QUANTITY NUMBER(
STORY CLOB
HAVE_INVOICE NOT NULL NUMBER(
HAVE_GUARANTEE NOT NULL NUMBER(
STUFF_STATUS NOT NULL NUMBER(
APPROVE_STATUS NOT NULL NUMBER(
OLD_STARTS NOT NULL DATE
ZOO VARCHAR
PROMOTED_STATUS NOT NULL NUMBER(
REPOST_TYPE CHAR(
REPOST_TIMES NOT NULL NUMBER(
SECURE_TRADE_AGREE NOT NULL NUMBER(
SECURE_TRADE_TRANSACTION_FEE VARCHAR
SECURE_TRADE_ORDINARY_POST_FEE NUMBER
SECURE_TRADE_FAST_POST_FEE NUMBER
表記錄數及大小
SQL> select count(*) from auction_auctions;
COUNT(*)
SQL> select segment_name
SEGMENT_NAME BYTES BLOCKS
AUCTION_AUCTIONS
表上原有的索引
create index ind_old on auction_auctions(closed
SQL> select segment_name
SEGMENT_NAME BYTES BLOCKS
IND_OLD
表和索引都已經分析過
SQL> set autotrace trace;
SQL> SELECT * FROM (SELECT T
Execution Plan
es=
(Cost=
=
Statistics
我們可以看到這條sql語句通過索引范圍掃描找到最裡面的結果集
我們來看一下這個索引建的到底合不合理
select count(distinct ends) from auction_auctions;
COUNT(DISTINCTENDS)
SQL> select count(distinct category) from auction_auctions;
COUNT(DISTINCTCATEGORY)
SQL> select count(distinct closed) from auction_auctions;
COUNT(DISTINCTCLOSED)
SQL> select count(distinct approve_status) from auction_auctions;
COUNT(DISTINCTAPPROVE_STATUS)
頁索引裡列平均存儲長度
SQL> select avg(vsize(ends)) from auction_auctions;
AVG(VSIZE(ENDS))
SQL> select avg(vsize(closed)) from auction_auctions;
AVG(VSIZE(CLOSED))
SQL> select avg(vsize(category)) from auction_auctions;
AVG(VSIZE(CATEGORY))
SQL> select avg(vsize(approve_status)) from auction_auctions;
AVG(VSIZE(APPROVE_STATUS))
我們來估算一下各種組合索引的大小
column distinct num column len
ends
category
closed
approve_status
index
en
From:http://tw.wingwit.com/Article/program/Oracle/201311/18323.html