表结构如(其中姓名不唯一,数据库是PGSQL):
user(姓名,性别,年龄)
temp(姓名,性别,年龄)SQL语句如下:
UPDATE user set 年龄 = temp.年龄
FROM temp
WHERE user.姓名 = temp.姓名 and user.性别 = temp.性别我现在主表有两万条记录,临时表有一万条,从开始运行此SQL到现在将近5000千秒了还在跑,效率实在低下,哎。 
于是我想到用这样的句式:UPDATE TAB SET C=(子查询) ,但是在手册上看了半天才发现,PGSQL不支持这样的子查询。
我网上又查了,再改为:
UPDATE user INNER JOIN temp ON user.姓名 = temp.姓名 and user.性别 = temp.性别
SET user.年龄 = temp.年龄还是报错。这不,没主意了,所以特此发帖向大家讨教来了,我是第一次来这个版块,大家可要多多光照啊!

解决方案 »

  1.   

      temp表设置一个索引,和user表联系起来
      

  2.   

    现在4秒多,可以了,结贴。thanks!!  >>user_key_tree...
    Inserted into temp  9744/19996 records(58.6621 seconds).
    Inserted into temp 19481/19996 records(59.1150 seconds).
    Inserted into temp 19996/19996 records(1.0320 seconds).
    start update, updated 19996/19996 records(4.3866 seconds).
    start add new, added     0/19996 records(0.1325 seconds).
        All count 19996/19996 records At user_key_tree.
        Timer: 126.3738 secondes