mysql創(chuàng)建Bitmap_Join_Indexes中的約束與索引
更新時間:2008年04月07日 20:41:03 作者:
現(xiàn)象:創(chuàng)建Bitmap Join Indexes時出現(xiàn)ORA-25954報錯: 維的主鍵或唯一約束條件缺失。 53vi.Com
原因:受到約束與索引的影響。
測試過程如下:
create table sales
as select * from sh.sales;
create table customers
as
select * from sh.customers;
create unique index CUST_ID_un on customers(CUST_ID);
創(chuàng)建:
Bitmap Join Indexes
create bitmap index sales_cust_gender_bjix
on sales(customers.cust_gender)
from sales,customers
where sales.cust_id=customers.cust_id;
報錯如下:
第 3 行出現(xiàn)錯誤:
ORA-25954: 維的主鍵或唯一約束條件缺失
案例分析:在此處盡管定義了對表customers的唯一性索引,但是該索引并沒有對表customers并沒有唯一性約束,即表示唯一性索引并不表示對表進行唯一性約束;但是如果加了唯一性的約束,就不會出現(xiàn)報錯,示例如下:
SQL> ALTER TABLE customers
2 MODIFY (cust_id CONSTRAINT customers_un unique);
表已更改。
SQL> create bitmap index sales_cust_gender_bjix
2 on sales(customers.cust_gender)
3 from sales,customers
4 where sales.cust_id=customers.cust_id;
索引已創(chuàng)建。
結(jié)論:
只要加了唯一性的約束,創(chuàng)建BJI則不會報錯。
create table sales
as select * from sh.sales;
create table customers
as
select * from sh.customers;
create unique index CUST_ID_un on customers(CUST_ID);
創(chuàng)建:
Bitmap Join Indexes
create bitmap index sales_cust_gender_bjix
on sales(customers.cust_gender)
from sales,customers
where sales.cust_id=customers.cust_id;
報錯如下:
第 3 行出現(xiàn)錯誤:
ORA-25954: 維的主鍵或唯一約束條件缺失
案例分析:在此處盡管定義了對表customers的唯一性索引,但是該索引并沒有對表customers并沒有唯一性約束,即表示唯一性索引并不表示對表進行唯一性約束;但是如果加了唯一性的約束,就不會出現(xiàn)報錯,示例如下:
SQL> ALTER TABLE customers
2 MODIFY (cust_id CONSTRAINT customers_un unique);
表已更改。
SQL> create bitmap index sales_cust_gender_bjix
2 on sales(customers.cust_gender)
3 from sales,customers
4 where sales.cust_id=customers.cust_id;
索引已創(chuàng)建。
結(jié)論:
只要加了唯一性的約束,創(chuàng)建BJI則不會報錯。
相關(guān)文章
mysql隨機查詢?nèi)舾蓷l數(shù)據(jù)的方法
這篇文章主要介紹了mysql中獲取隨機內(nèi)容的方法,需要的朋友可以參考下2013-10-10
window下mysql 8.0.15 winx64安裝配置方法圖文教程
這篇文章主要為大家詳細介紹了window下mysql 8.0.15 winx64安裝配置方法圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-03-03
Mysql聯(lián)合查詢UNION和Order by同時使用報錯問題的解決辦法
很多朋友剛使用聯(lián)合查詢UNION的時候常常會理所當然的將聯(lián)合查詢理解為把沒一個子查詢的結(jié)果集組合成一個大的結(jié)果集2014-04-04
提升MySQL查詢效率及查詢速度優(yōu)化的四個方法詳析
查詢語句的優(yōu)化是提高MySQL查詢速度的重要方法,可以通過使用JOIN語句、子查詢、優(yōu)化where子句等方式來減少查詢的時間,下面這篇文章主要給大家介紹了關(guān)于提升MySQL查詢效率及查詢速度優(yōu)化的四個方法,需要的朋友可以參考下2023-04-04

