and acc_book_code = t_acc_book_code and center_code = "000000" and item_code = t_item_code and direction_idx = t_dir_idx_val1 and direction_other = t_dir_oth_val1); 在SQL 语句中,where 条件中有or 的语句,where 条件尽量用大组合,而不要用小组合。
3.7. 关于使用put , execute 来代替insert 提高效率在做数据转换或登录大批量数据时,用put 或execute 替代insert ,将使效率大幅度提高。因为在循环体内,减少了对insert 的语法检查及预处理的时间。 Put 的用法如下: let t_pre_1 = "insert into rta1 values ", "(?,?,?,?,?,?,?,?,?,?,", "?,?,?,?,?,?,?,?,?,?,", "?,?,?,?,?,?,?,?,?,?,", "?,?,?,?,?,?,?,?,?,?,", "?,?,?,?)" prepare pre_rta1_1 from t_pre_1 declare cur_ins_1 cursor for pre_rta1_1 open cur_ins_1 循环体(while , for , foreach) { put cur_ins_1 from p_rta1.* } close cur_ins_1 execute 的语法如下: let t_pre_1 = "insert into rta1 values " "(?,?,?,?,?,?,?,?,?,?,", "?,?,?,?,?,?,?,?,?,?,", "?,?,?,?,?,?,?,?,?,?,", "?,?,?,?,?,?,?,?,?,?,", "?,?,?,?)" prepare pre_rta1_1 from t_pre_1 循环体(while , for , foreach) { execute pre_rta1_1 using p_rta1.* } 使用put 必须注意以下内容: u put 语句必须在事物中。 u put 语句执行完后,马上从库中select 不一定能取到数 3.8. 使用隔离级别(isolation) 共有四种隔离级别 Dirty read Commited read Cursor stability Repeatable read <一> dirty read 可能读到未提交(commited)的记录,可能读到最后被回滚的记录,该记录是一个phantom。 在一些查询中,使用此隔离级别,可提高效率。因为不受其他进程锁表,锁记录的影响。
<二> committed read 读到的数据均为提交后的数据。两个进程可同时update 同一条记录。(缺省的隔离级别) <三> cursor stability 当隔离级别设置为cursor stability 时,在某一游标内,当前记录不能被其他 的进程update,delete ,但游标内其他的记录可被其他进程update ,delete 。 <四> repeatable read 当隔离级别设置为repeatable read 时,在某一游标内有两种情况 1. 该游标的where 子句有索引,则满足条件的所有记录均不能被其他进程 update ,delete 。(该索引的搜索树的所有节点) 2. 该游标的where 子句不在索引上,则该表的所有记录均不能被其他进程 update,delete 。 所以,当使用repeatable read 时,最好有索引,否则相当于锁表,极大损害系统效率。 3.9. 使用优化器(update statistics) 对表,存储过程的优化的语法如下: update statistics [low ] for procedure .. [ medium] for table tablename [colname] resolution percent . conf [high ] 优化使系统表的信息与实际一致,使搜索树的路径最优。 同时,整理索引树。 例: 1. update statistics for table 2. update statistics for procedure 3. update statistics for table rta1(bm_cert) 4. update statistics high for table rta1(bm_cert) resolution 0.5
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] 下一页
|