mysql創(chuàng)建Bitmap_Join_Indexes中的約束與索引
更新時(shí)間:2008年04月07日 20:41:03 作者:
現(xiàn)象:創(chuàng)建Bitmap Join Indexes時(shí)出現(xiàn)ORA-25954報(bào)錯(cuò): 維的主鍵或唯一約束條件缺失。 53vi.Com
原因:受到約束與索引的影響。
測(cè)試過(guò)程如下:
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;
報(bào)錯(cuò)如下:
第 3 行出現(xiàn)錯(cuò)誤:
ORA-25954: 維的主鍵或唯一約束條件缺失
案例分析:在此處盡管定義了對(duì)表customers的唯一性索引,但是該索引并沒(méi)有對(duì)表customers并沒(méi)有唯一性約束,即表示唯一性索引并不表示對(duì)表進(jìn)行唯一性約束;但是如果加了唯一性的約束,就不會(huì)出現(xiàn)報(bào)錯(cuò),示例如下:
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則不會(huì)報(bào)錯(cuò)。
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;
報(bào)錯(cuò)如下:
第 3 行出現(xiàn)錯(cuò)誤:
ORA-25954: 維的主鍵或唯一約束條件缺失
案例分析:在此處盡管定義了對(duì)表customers的唯一性索引,但是該索引并沒(méi)有對(duì)表customers并沒(méi)有唯一性約束,即表示唯一性索引并不表示對(duì)表進(jìn)行唯一性約束;但是如果加了唯一性的約束,就不會(huì)出現(xiàn)報(bào)錯(cuò),示例如下:
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則不會(huì)報(bào)錯(cuò)。
相關(guān)文章
mysql隨機(jī)查詢?nèi)舾蓷l數(shù)據(jù)的方法
這篇文章主要介紹了mysql中獲取隨機(jī)內(nèi)容的方法,需要的朋友可以參考下2013-10-10window下mysql 8.0.15 winx64安裝配置方法圖文教程
這篇文章主要為大家詳細(xì)介紹了window下mysql 8.0.15 winx64安裝配置方法圖文教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-03-03Mysql聯(lián)合查詢UNION和Order by同時(shí)使用報(bào)錯(cuò)問(wèn)題的解決辦法
很多朋友剛使用聯(lián)合查詢UNION的時(shí)候常常會(huì)理所當(dāng)然的將聯(lián)合查詢理解為把沒(méi)一個(gè)子查詢的結(jié)果集組合成一個(gè)大的結(jié)果集2014-04-04MySql如何查看索引并實(shí)現(xiàn)優(yōu)化
這篇文章主要介紹了MySql如何查看索引并實(shí)現(xiàn)優(yōu)化,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-12-12提升MySQL查詢效率及查詢速度優(yōu)化的四個(gè)方法詳析
查詢語(yǔ)句的優(yōu)化是提高M(jìn)ySQL查詢速度的重要方法,可以通過(guò)使用JOIN語(yǔ)句、子查詢、優(yōu)化where子句等方式來(lái)減少查詢的時(shí)間,下面這篇文章主要給大家介紹了關(guān)于提升MySQL查詢效率及查詢速度優(yōu)化的四個(gè)方法,需要的朋友可以參考下2023-04-04