【请问】从两个相关表update其中一个表的两个字段,效率很低,两个小时了,还没结束,为什么?(各有数据50w/10w)
为什么下面的SQL语句执行N慢,有没有效率更高的办法,谢谢各位大虾.
1.SQL语句如下:
---------------------------------------------------------------
update new_Table a
set (a.AreaId,a.TypeId) = (select b.AreaId,b.TypeId
from DataTable b
where substr(trim(a.Col),1,length(trim(b.Num))) = trim(b.Col));
2.表结构如下:
---------------------------------------------------------------
new_Table 有50w左右数据,DataTable 有近10w数据,
new_Table.Col 前面的几位值与 DataTable.Num关联(相等).
3.表结构如下:
---------------------------------------------------------------
-- ============================================================
-- Table: new_Table
-- ============================================================
create table new_Table
(
Col CHAR(15) not null,--数据位数>9
AreaId CHAR(6) null ,
CardTypeId CHAR(6) not null,
constraint PK_NEW_TABLE primary key (Col)
)
/
-- ============================================================
-- Table: DataTable
-- ============================================================
create table DataTable
(
Num CHAR(15) not null,--数据位数固定为3/4/7
AreaId CHAR(6) null ,
CardTypeId CHAR(6) not null,
constraint PK_DATATABLE primary key (Num)
)
/