楼主: ~贝贝~

[Tips] 《DB2设计与性能优化》作者做客ITPUB,举办DB2提问有奖活动,活动结束!

[复制链接]
论坛徽章:
304
山治
日期:2017-03-02 08:50:07ITPUB十周年纪念徽章
日期:2011-11-03 15:15:25ITPUB十周年纪念徽章
日期:2011-11-03 15:14:55ITPUB十周年纪念徽章
日期:2011-11-03 15:09:35ITPUB十周年纪念徽章
日期:2011-11-03 14:01:59ITPUB十周年纪念徽章
日期:2011-11-03 15:07:35ITPUB十周年纪念徽章
日期:2011-11-03 14:24:42ITPUB十周年纪念徽章
日期:2011-11-03 14:23:57ITPUB十周年纪念徽章
日期:2011-11-03 14:22:38ITPUB十周年纪念徽章
日期:2011-11-03 14:21:34
51#
发表于 2011-5-12 15:46 | 只看该作者
很早就听说DB2数据库了!但一直没接触过。
请问:
DB2 和Oracle的语法区别大吗?
存储过程和函数和Oracle有什么区别?听说DB2的存储过程调试起来比较复杂。
目前DB2最新使用的是什么版本?有没有免费版?
Oracle或SQL Server的数据通过什么方式移植到DB2里?
维运起来方便吗?

使用道具 举报

回复
论坛徽章:
190
指数菠菜纪念章
日期:2012-11-01 17:01:54指数菠菜纪念章
日期:2012-11-01 17:01:54指数菠菜纪念章
日期:2012-11-01 17:01:54指数菠菜纪念章
日期:2012-11-01 17:01:54指数菠菜纪念章
日期:2012-11-01 17:01:54指数菠菜纪念章
日期:2013-04-02 08:53:29指数菠菜纪念章
日期:2012-11-01 17:01:54指数菠菜纪念章
日期:2012-11-01 17:01:54指数菠菜纪念章
日期:2012-11-01 17:01:54NBA常规赛纪念章
日期:2011-04-15 13:34:11
52#
发表于 2011-5-12 17:01 | 只看该作者
DB2和sql server ,oracle的優缺點?

使用道具 举报

回复
论坛徽章:
1
2012新春纪念徽章
日期:2012-01-04 11:58:18
53#
发表于 2011-5-12 17:52 | 只看该作者
哦,你需要设置下面的注册变量,然后重启数据库才有效。 你可以再试一下!

  1. db2set DB2_OPTPROFILE=YES;
  2. db2stop force;
  3. db2start;
复制代码



原帖由 〇〇 于 2011-5-12 14:29 发表
请问我用了NLJOIN优化提示,可是执行计划还是HSJOIN

Statement:
  
  select count(*)
  from t1, t2
  where t1.id=t2.id /*   
             */


Section Code Page = 1208

Estimated Cost = 15.168448
Estimated Cardinality = 1.000000

Access Table Name = DB2INST1.T2  ID = 4,13
|  #Columns = 1
|  Skip Inserted Rows
|  Avoid Locking Committed Data
|  Currently Committed for Cursor Stability
|  May participate in Scan Sharing structures
|  Scan may start anywhere and wrap, for completion
|  Fast scan, for purposes of scan sharing management
|  Scan can be throttled in scan sharing management
|  Relation Scan
|  |  Prefetch: Eligible
|  Lock Intents
|  |  Table: Intent Share
|  |  Row  : Next Key Share
|  Sargable Predicate(s)
|  |  Process Build Table for Hash Join
Hash Join
|  Estimated Build Size: 4000   
|  Estimated Probe Size: 4000   
|  Access Table Name = DB2INST1.T1  ID = 4,12
|  |  #Columns = 1
|  |  Skip Inserted Rows
|  |  Avoid Locking Committed Data
|  |  Currently Committed for Cursor Stability
|  |  May participate in Scan Sharing structures
|  |  Scan may start anywhere and wrap, for completion
|  |  Fast scan, for purposes of scan sharing management
|  |  Scan can be throttled in scan sharing management
|  |  Relation Scan
|  |  |  Prefetch: Eligible
|  |  Lock Intents
|  |  |  Table: Intent Share
|  |  |  Row  : Next Key Share
|  |  Sargable Predicate(s)
|  |  |  Process Probe Table for Hash Join
Aggregation
|  Column Function(s)
Return Data to Application
|  #Columns = 1

End of section

使用道具 举报

回复
论坛徽章:
2110
亚特兰大老鹰
日期:2015-01-05 11:33:18亚特兰大老鹰
日期:2015-01-05 11:33:18亚特兰大老鹰
日期:2015-01-05 11:33:18亚特兰大老鹰
日期:2015-01-05 11:33:18亚特兰大老鹰
日期:2015-01-05 11:33:18亚特兰大老鹰
日期:2015-01-05 11:33:18亚特兰大老鹰
日期:2015-01-05 11:33:18亚特兰大老鹰
日期:2015-01-05 11:33:18亚特兰大老鹰
日期:2015-01-05 11:33:18亚特兰大老鹰
日期:2015-01-05 11:33:18
54#
发表于 2011-5-12 18:25 | 只看该作者
DB2是不是适合任何数据库的需求?

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
55#
发表于 2011-5-12 18:40 | 只看该作者
为什么我启用了分区内并行,反而更慢了

468.879329 seconds 482.459168
  3.456943 seconds   4.283617
35.196633 seconds  49.522005
24.756155 seconds  25.135826
27.720584 seconds  30.382384
103.166410 seconds 100.084318
40.526446 seconds  47.550015
34.452728 seconds  40.439229
88.036224 seconds  87.582887
30.404406 seconds  36.627290
  6.502055 seconds   7.831795
38.336033 seconds  33.335061
49.450705 seconds  66.658736
32.759258 seconds  32.816498
36.062827 seconds  36.917765
  8.496194 seconds  19.588469
27.698119 seconds  23.122384
167.040236 seconds 234.650377
40.308232 seconds
587.439039 seconds
61.395391 seconds
60.756332 seconds

启用步骤
[db2inst1@750_ora1a:/home/db2inst1]#>db2batch -d tpch -f /arch/IBM/q01-22_f.txt > /tmp/q01-22_f_zip.log


[db2inst1@750_ora1a:/home/db2inst1]#>[db2inst1@750_ora1a:/home/db2inst1]#>[db2inst1@750_ora1a:/home/db2inst1]#>
[db2inst1@750_ora1a:/home/db2inst1]#>db2 get dbm cfg|grep PARA
Enable intra-partition parallelism     (INTRA_PARALLEL) = NO
[db2inst1@750_ora1a:/home/db2inst1]#>db2 update dbm cfg using INTRA_PARALLEL YES
DB20000I  The UPDATE DATABASE MANAGER CONFIGURATION command completed
successfully.

[db2inst1@750_ora1a:/home/db2inst1]#>db2 get dbm cfg|grep PARA
Enable intra-partition parallelism     (INTRA_PARALLEL) = YES
[db2inst1@750_ora1a:/home/db2inst1]#>db2 get dbm cfg|grep DEGR
Maximum query degree of parallelism   (MAX_QUERYDEGREE) = ANY
[db2inst1@750_ora1a:/home/db2inst1]#>db2stop force
05/12/2011 17:14:57     0   0   SQL1064N  DB2STOP processing was successful.
SQL1064N  DB2STOP processing was successful.
[db2inst1@750_ora1a:/home/db2inst1]#>db2start
05/12/2011 17:15:04     0   0   SQL1063N  DB2START processing was successful.
SQL1063N  DB2START processing was successful.
[db2inst1@750_ora1a:/home/db2inst1]#>db2expln -d tpch -q "select count(*) from tpch.nation,tpch.region" -t

DB2 Universal Database Version 9.7, 5622-044 (c) Copyright IBM Corp. 1991, 2009
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL and XQUERY Explain Tool

DB2 Universal Database Version 9.7, 5622-044 (c) Copyright IBM Corp. 1991, 2009
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL and XQUERY Explain Tool

******************** DYNAMIC ***************************************

==================== STATEMENT ==========================================

        Isolation Level          = Cursor Stability
        Blocking                 = Block Unambiguous Cursors
        Query Optimization Class = 5

        Partition Parallel       = No
        Intra-Partition Parallel = Yes (Bind Degree = ANY  )

        SQL Path                 = "SYSIBM", "SYSFUN", "SYSPROC", "SYSIBMADM",
                                   "DB2INST1"


Statement:
  
  select count(*)
  from tpch.nation, tpch.region

Intra-Partition Parallelism Degree = 48

Section Code Page = 1208

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
56#
发表于 2011-5-12 18:53 | 只看该作者
原帖由 李玉明-421 于 2011-5-12 17:52 发表
哦,你需要设置下面的注册变量,然后重启数据库才有效。 你可以再试一下!

db2set DB2_OPTPROFILE=YES;
db2stop force;
db2start;



好了,谢谢

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
57#
发表于 2011-5-13 06:33 | 只看该作者
原帖由 〇〇 于 2011-5-12 18:40 发表
为什么我启用了分区内并行,反而更慢了

468.879329 seconds 482.459168
  3.456943 seconds   4.283617
35.196633 seconds  49.522005
24.756155 seconds  25.135826
27.720584 seconds  30.382384
103.166410 seconds 100.084318
40.526446 seconds  47.550015
34.452728 seconds  40.439229
88.036224 seconds  87.582887
30.404406 seconds  36.627290
  6.502055 seconds   7.831795
38.336033 seconds  33.335061
49.450705 seconds  66.658736
32.759258 seconds  32.816498
36.062827 seconds  36.917765
  8.496194 seconds  19.588469
27.698119 seconds  23.122384
167.040236 seconds 234.650377
40.308232 seconds
587.439039 seconds
61.395391 seconds
60.756332 seconds

启用步骤
[db2inst1@750_ora1a:/home/db2inst1]#>db2batch -d tpch -f /arch/IBM/q01-22_f.txt > /tmp/q01-22_f_zip.log


[db2inst1@750_ora1a:/home/db2inst1]#>[db2inst1@750_ora1a:/home/db2inst1]#>[db2inst1@750_ora1a:/home/db2inst1]#>
[db2inst1@750_ora1a:/home/db2inst1]#>db2 get dbm cfg|grep PARA
Enable intra-partition parallelism     (INTRA_PARALLEL) = NO
[db2inst1@750_ora1a:/home/db2inst1]#>db2 update dbm cfg using INTRA_PARALLEL YES
DB20000I  The UPDATE DATABASE MANAGER CONFIGURATION command completed
successfully.

[db2inst1@750_ora1a:/home/db2inst1]#>db2 get dbm cfg|grep PARA
Enable intra-partition parallelism     (INTRA_PARALLEL) = YES
[db2inst1@750_ora1a:/home/db2inst1]#>db2 get dbm cfg|grep DEGR
Maximum query degree of parallelism   (MAX_QUERYDEGREE) = ANY
[db2inst1@750_ora1a:/home/db2inst1]#>db2stop force
05/12/2011 17:14:57     0   0   SQL1064N  DB2STOP processing was successful.
SQL1064N  DB2STOP processing was successful.
[db2inst1@750_ora1a:/home/db2inst1]#>db2start
05/12/2011 17:15:04     0   0   SQL1063N  DB2START processing was successful.
SQL1063N  DB2START processing was successful.
[db2inst1@750_ora1a:/home/db2inst1]#>db2expln -d tpch -q "select count(*) from tpch.nation,tpch.region" -t

DB2 Universal Database Version 9.7, 5622-044 (c) Copyright IBM Corp. 1991, 2009
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL and XQUERY Explain Tool

DB2 Universal Database Version 9.7, 5622-044 (c) Copyright IBM Corp. 1991, 2009
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL and XQUERY Explain Tool

******************** DYNAMIC ***************************************

==================== STATEMENT ==========================================

        Isolation Level          = Cursor Stability
        Blocking                 = Block Unambiguous Cursors
        Query Optimization Class = 5

        Partition Parallel       = No
        Intra-Partition Parallel = Yes (Bind Degree = ANY  )

        SQL Path                 = "SYSIBM", "SYSFUN", "SYSPROC", "SYSIBMADM",
                                   "DB2INST1"


Statement:
  
  select count(*)
  from tpch.nation, tpch.region

Intra-Partition Parallelism Degree = 48

Section Code Page = 1208

等了一晚上也不出结果,
用fore application all终止,发现结果已经输出,还挂在那里干什么?

q01-22_f_zip_para.rar

14.04 KB, 下载次数: 2

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
58#
发表于 2011-5-13 07:46 | 只看该作者
truncate后load,runstats
怎么查询还会出错?
[db2inst1@750_ora1a:/home/db2inst1]#>db2 truncate table tpch.lineitem
DB20000I  The SQL command completed successfully.
[db2inst1@750_ora1a:/home/db2inst1]#>
[db2inst1@750_ora1a:/home/db2inst1]#>
[db2inst1@750_ora1a:/home/db2inst1]#>date;db2 load from /arch/IBM/lineitem.tbl of del MODIFIED BY COLDELX7C MESSAGES /tmp/msgl2.tmp insert into tpch.lineitem ;date
Fri May 13 07:01:53 GMT+08:00 2011



Number of rows read         = 59986052
Number of rows skipped      = 0
Number of rows loaded       = 59986052
Number of rows rejected     = 0
Number of rows deleted      = 0
Number of rows committed    = 59986052

Fri May 13 07:13:18 GMT+08:00 2011
[db2inst1@750_ora1a:/home/db2inst1]#>[db2inst1@750_ora1a:/home/db2inst1]#>[db2inst1@750_ora1a:/home/db2inst1]#>
[db2inst1@750_ora1a:/home/db2inst1]#>time db2 "runstats on table tpch.lineitem WITH DISTRIBUTION AND INDEXES ALL"


DB20000I  The RUNSTATS command completed successfully.

real    5m52.43s
user    0m0.02s
sys     0m0.00s
[db2inst1@750_ora1a:/home/db2inst1]#>db2 "select count(*) from tpch.lineitem"

1         
-----------
SQL0668N  Operation not allowed for reason code "1" on table "TPCH.LINEITEM".  
SQLSTATE=57016

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
59#
发表于 2011-5-13 07:57 | 只看该作者
google了一下
SQL0668N Operation not allowed for reason code "1" on table "<table-name>".
SQLSTATE=57016
This error occurs when the table is in the Check Pending state. The Check Pending state occurs when the integrity of the table is not enforced and the content of the table is invalid. This error can also occur when an operation on a parent table or an underlying table that is not in a Check Pending state, but its dependent tables are in a Check Pending state.

To bring the table out of the Check Pending state, do the following:

Type the following commands at the command prompt:
db2 connect to wcamart user user_id using password
db2 set integrity for table_name immediate checked

但是我还是不明白,他是指主外键?db2导入过程中不检查?

使用道具 举报

回复
论坛徽章:
1
ITPUB知识分享者
日期:2011-04-27 17:19:08
60#
发表于 2011-5-13 09:06 | 只看该作者
原帖由 李玉明-421 于 2011-5-12 13:14 发表


4. 可以用DB2的optguidelines, 指定hash连接
SELECT * FROM T1 , T2  where t1.c1 = t2.c1
/*       */ ;

5. 表压缩可以减少磁盘IO,在内存中处理压缩页时,首先减压缩这个页,然后做扫描页并作处理。压缩和解压大概会增加5%~10%的CPU时间,但由于处理查询时,IO的开销比CPU大,减少的IO开销得到的好处远大于增加的CPU开销。


对于读操作,如果设计合理,表压缩后,每次DB2从磁盘读出表数据到内存时,读到的都是压缩后的数据,所需I/O次数会比压缩前减少很多,节省了I/O时间;当然,数据到内存后需要解压缩并耗费cpu时间。压缩后是否变慢取决于多耗费的CPU时间是否大于节省的I/O时间。

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表