楼主: 〇〇

[有奖问答] 用过程语言实现group by cube的代码挑战赛

[复制链接]
论坛徽章:
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
81#
 楼主| 发表于 2010-3-5 13:09 | 只看该作者
改为
text *cb = (text *) "\
    CREATE OR REPLACE PACKAGE BODY update_parts AS\
        PROCEDURE add_parts (n            IN   INTEGER,\
                             descrip      IN   part_description,\
                             partno       IN   part_number) is\
        BEGIN\
            FORALL i IN 1..n \
                INSERT INTO part_nos\
                    VALUES (partno(i), descrip(i));\
        END add_parts;\
    END update_parts;";

12万行很快

D:\app\instantclient10_1>D:\app\oci\samples\blt
Connecting to ORACLE...
Dropping table...
Creating table...
Creating package...
Creating package body...
Parsing PL/SQL block...time=655

Binding arrays...
Executing block...time=187
SQL> select count(*) from part_nos;

  COUNT(*)
----------
    120000

1080000行

D:\app\instantclient10_1>D:\app\oci\samples\blt
Connecting to ORACLE...
Dropping table...
Creating table...
Creating package...
Creating package body...
Parsing PL/SQL block...time=733

Binding arrays...
Executing block...time=1544
SQL> select count(*) from part_nos;

  COUNT(*)
----------
   1080000

使用道具 举报

回复
论坛徽章:
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
82#
 楼主| 发表于 2010-3-5 15:19 | 只看该作者
test code

ocisamples.rar

6.41 KB, 下载次数: 5

使用道具 举报

回复
论坛徽章:
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
83#
 楼主| 发表于 2010-3-5 19:15 | 只看该作者
还剩下一个难点没有解决
翻遍网络,好像非direct path只能调用存储过程forall才能批量装载

使用道具 举报

回复
论坛徽章:
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
84#
 楼主| 发表于 2010-3-8 14:28 | 只看该作者
作了一个完整的,还有错误
create table yourcube
(
C1 NUMBER(30,0),
C2 NUMBER(30,0),
C3 NUMBER(30,0),
C4 NUMBER(30,0),
SV NUMBER(30,0),  
CV NUMBER(30,0),  
GId NUMBER(30,0)   
);

D:\app\instantclient10_1>..\map9b LT/LT@10.6.132.43/orcl query="select c1,c2,c3,c4,v from t" file=NUL

       0 rows exported at 2010-03-08 14:38:12
recn=0
  500000 rows exported at 2010-03-08 14:38:13
recn=500000
1000000 rows exported at 2010-03-08 14:38:14
         output file  closed at 1000000 rows.

sum=1
sum(c1+c2+c3+v)=500111497488
sum(c4)=51690810
从数据库把表读入内存3291ms
4,5,67,114,152760
申请map内存16ms
申请一层内存15ms
新建一层节点500ms,recn=1000000,每毫秒读2000行,每毫秒写2000节点
申请后面内存31ms,1000000
新建后面节点2277ms,recn=2299600,每毫秒读439行key,每毫秒写570节点
0,first=2,renc=0
1,first=1000007F,renc=1000003
2,first=20007F00,renc=1000002
3,first=30007F7F,renc=2260123
4,first=407F0000,renc=1000001
5,first=507F007F,renc=2260125
6,first=607F7F00,renc=2284774
7,first=707F7F7F,renc=2284669
8,first=8F000000,renc=1000000
9,first=9F00007F,renc=2260124
10,first=AF007F00,renc=2273610
11,first=BF007F7F,renc=2284668
12,first=CF7F0000,renc=2284775
13,first=DF7F007F,renc=2299366
14,first=EF7F7F00,renc=2299485
15,first=FF7F7F7F,renc=2299599
汇总后面节点140ms,recn=2299600,每毫秒读7142行,每毫秒写9282行

Total number of rows to be inserted is 1000000

Connected to ORACLE as ocitest
插入结果表time=2558
释放所有动态内存2777ms,2299600
释放所有map内存203ms,2299600
总时间5975ms,2299600
3步(读入+运算+写出)总时间9266ms

Exiting with SUCCESS status 0

[ 本帖最后由 〇〇 于 2010-3-8 16:45 编辑 ]

map9b.rar

11.21 KB, 下载次数: 9

使用道具 举报

回复
论坛徽章:
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
85#
 楼主| 发表于 2010-3-8 15:10 | 只看该作者
汇总后面节点140ms,recn=2299600,每毫秒读7142行,每毫秒写9282行

Connected to ORACLE as ocitest

Total number of rows to be inserted is 1000000
插入结果表time=2340

Total number of rows to be inserted is 1299600
插入结果表time=3650
释放所有动态内存16ms,2299600
释放所有map内存203ms,2299600
总时间9470ms,2299600
3步(读入+运算+写出)总时间12792ms

Exiting with SUCCESS status 0

使用道具 举报

回复
论坛徽章:
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
86#
 楼主| 发表于 2010-3-8 19:26 | 只看该作者
能输出部分正确的结果了,写入null的问题没有解决

map9c.rar

9.19 KB, 下载次数: 8

使用道具 举报

回复
论坛徽章:
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
87#
 楼主| 发表于 2010-3-8 21:12 | 只看该作者
删除没用的注释
D:\lt\dl>map9c LT/LT query="select * from(select mod(level,9)c1,mod(level,19)c2,mod(level,109)c3,mod(case when mod(level,13)>0 then le
vel end ,113)c4, level v from dual connect by level<=1E6)" file=NUL

       0 rows exported at 2010-03-08 21:04:46
recn=0
  500000 rows exported at 2010-03-08 21:04:49
recn=500000
1000000 rows exported at 2010-03-08 21:04:52
         output file  closed at 1000000 rows.

sum=1
sum(c1+c2+c3+v)=500067498723
sum(c4)=51690810
从数据库把表读入内存6187ms
4,5,67,114,152760
申请map内存0ms
申请一层内存0ms
新建一层节点484ms,recn=941716,每毫秒读2066行,每毫秒写1945节点
申请后面内存16ms,941716
新建后面节点1000ms,recn=1346870,每毫秒读941行key,每毫秒写405节点
0,first=29,renc=0
1,first=1000007F,renc=941719
2,first=20007F00,renc=941718
3,first=30007F7F,renc=1327777
4,first=407F0000,renc=941717
5,first=507F007F,renc=1327779
6,first=607F7F00,renc=1333194
7,first=707F7F7F,renc=1333167
8,first=8F000000,renc=941716
9,first=9F00007F,renc=1327778
10,first=AF007F00,renc=1331000
11,first=BF007F7F,renc=1333166
12,first=CF7F0000,renc=1333195
13,first=DF7F007F,renc=1346646
14,first=EF7F7F00,renc=1346755
15,first=FF7F7F7F,renc=1346869
汇总后面节点32ms,recn=1346870,每毫秒读29428行,每毫秒写12661行

Total number of rows to be inserted is 100
插入结果表time=15

Total number of rows to be inserted is 100
插入结果表time=0
释放所有动态内存0ms,1346870
释放所有map内存313ms,1346870
总时间1891ms,1346870
3步(读入+运算+写出)总时间8078ms

Exiting with SUCCESS status 0

D:\lt\dl>

[ 本帖最后由 〇〇 于 2010-3-9 07:59 编辑 ]

map9c.rar

43.09 KB, 下载次数: 7

使用道具 举报

回复
论坛徽章:
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
88#
 楼主| 发表于 2010-3-9 12:38 | 只看该作者
用难看的方式实现了大整数和NULL
text *sqlstmt = (text *)"INSERT INTO yourcube (c1,c2,c3,c4,cv,sv,gid) \
values (decode(:c1,15,NULL,:c1),decode(:c2,127,NULL,:c2),decode(:c3,127,NULL,:c3),\
decode(:c4,127,NULL,:c4),:cv,:sv+:sv1*4294967296,:gid)";

速度慢很多
D:\app\instantclient10_1>..\map9d LT/LT@10.6.132.43/orcl query="select c1,c2,c3,c4,v from t" file=NUL

       0 rows exported at 2010-03-09 12:34:29
recn=0
  500000 rows exported at 2010-03-09 12:34:30
recn=500000
1000000 rows exported at 2010-03-09 12:34:32
         output file  closed at 1000000 rows.

sum=1
sum(c1+c2+c3+v)=500111497488
sum(c4)=51690810
从数据库把表读入内存3073ms
4,5,67,114,152760
申请map内存0ms
申请一层内存15ms
新建一层节点468ms,recn=1000000,每毫秒读2136行,每毫秒写2136节点
申请后面内存32ms,1000000
新建后面节点2121ms,recn=2299600,每毫秒读471行key,每毫秒写612节点
0,first=2,renc=0
1,first=1000007F,renc=1000003
2,first=20007F00,renc=1000002
3,first=30007F7F,renc=2260123
4,first=407F0000,renc=1000001
5,first=507F007F,renc=2260125
6,first=607F7F00,renc=2284774
7,first=707F7F7F,renc=2284669
8,first=8F000000,renc=1000000
9,first=9F00007F,renc=2260124
10,first=AF007F00,renc=2273610
11,first=BF007F7F,renc=2284668
12,first=CF7F0000,renc=2284775
13,first=DF7F007F,renc=2299366
14,first=EF7F7F00,renc=2299485
15,first=FF7F7F7F,renc=2299599
汇总后面节点140ms,recn=2299600,每毫秒读7142行,每毫秒写9282行

Total number of rows to be inserted is 1000000
插入结果表time=4618

Total number of rows to be inserted is 1299600
插入结果表time=5741
释放所有动态内存0ms,2299600
释放所有map内存218ms,2299600
总时间13603ms,2299600
3步(读入+运算+写出)总时间16676ms

Exiting with SUCCESS status 0

[ 本帖最后由 〇〇 于 2010-3-9 12:41 编辑 ]

map9d.rar

8.53 KB, 下载次数: 7

使用道具 举报

回复
论坛徽章:
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
89#
 楼主| 发表于 2010-3-9 13:04 | 只看该作者
还有错误
SQL> select count(*) from (select * from tcube minus select * from yourcube);

  COUNT(*)
----------
    140932
很奇怪
SQL> select gid,count(*)cnt from yourcube group by rollup(gid) order by 1;

       GID        CNT
---------- ----------
         0    1000001
         1     199782
         2     106708
         3        873
         4     144585
         5       1071
         6       1026
         7          9
         8     809047
         9      11543
        10      11058
        11         97
        12      13566
        13        119
        14        114
        15          1
              2299600

已选择17行。

SQL> select gid,count(*)cnt from tcube group by rollup(gid) order by 1;

       GID        CNT
---------- ----------
         0    1000000
         1     103887
         2      99522
         3        873
         4     122094
         5       1071
         6       1026
         7          9
         8     934620
         9      11543
        10      11058
        11         97
        12      13566
        13        119
        14        114
        15          1
              2299600

已选择17行。

SQL> select count(*) from (select * from yourcube minus select * from tcube);

  COUNT(*)
----------
    140931
个数不一样的gid都是2的n次幂

[ 本帖最后由 〇〇 于 2010-3-9 13:06 编辑 ]

使用道具 举报

回复
论坛徽章:
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
90#
 楼主| 发表于 2010-3-10 10:15 | 只看该作者
map9e.rar (8.56 KB, 下载次数: 25) void initialize_data(int colindex,ub1 *arr,
sword len,sb2 * indp,
ub2 *flen,
sword numinsert,int *k,int *C,int *v2) //copy data from big array to small array

{

     
      sword rowindex;                                               /* index */
      sword numchars;                     /* number of characters to extract */
      text *str = (text *)"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int y;
y=pass;//pass++
for (rowindex = 0; rowindex < numinsert; rowindex++,y++)
{
       
        switch(colindex)
        {
                case 0:        *((char *)arr+rowindex)=(char)((k[y]>>24)&15);break;
                case 1:        *((char *)arr+rowindex)=(char)((k[y]>>16)&255); break;
                case 2:        *((char *)arr+rowindex)=(char)((k[y]>>8)&255); break;  
                case 3:        *((char *)arr+rowindex)=(char)(k[y]&255); break;      
                case 4:        *((int *)arr+rowindex)=C[y]; break;
                case 5:        *((int *)arr+rowindex)=(*((__int64*)v2+y))&0xFFFFFFFFL; break;
                case 6:        *((char *)arr+rowindex)=(16+((k[y]>>24)>>4))&15; break;
                case 7:        *((int *)arr+rowindex)=((*((__int64*)v2+y))>>32)&0xFFFFFFFFL; break;
        }
flen[rowindex]=len;
indp[rowindex]=0; //赋值正常
//printf("%d,",indp[rowindex]);
//if((colindex==0 && (*((int *)arr+rowindex)==15))||((colindex>=1 && colindex <=3)&&(*((int *)arr+rowindex)==127)))
//if(colindex==0)
indp[rowindex]=-1;//赋值出错
}

附件这个例子插入NULL是正确的,同样的写法

void initialize_data(arr, len, flen, numinsert,indp)
ub1 *arr;
sword len;
ub2 *flen;
sword numinsert;
sb2 * indp;
{

      static int pass = 0;
      sword colindex;                                               /* index */
      sword numchars;                     /* number of characters to extract */
      text *str = (text *)"ABCDEFGHIJKLMNOPQRSTUVWXYZ";


      for (colindex = 0; colindex < numinsert; colindex++)
      {
          numchars = (pass * MAX_ROWS_PER_INSERT) + colindex + 1;
          memcpy((dvoid *)(arr + colindex*len), (dvoid *)str, numchars);
          *(arr + colindex*len + numchars ) = '\0';        /* null terminate */
          /*printf("iteration %d string is %s  length is %d\n",
                 pass, arr + colindex *len,
                 strlen((char *)(arr + colindex *len)));*/

/* GOTCHA!! - The null must be found within the length specified so add one */
/* or just use the max length allowed for the array element */

          *(flen + colindex) = strlen((char *)(arr + colindex*len)) + 1;
                               /* *(flen + colindex) = 30;  <--- or use this */
                             if(flen[colindex]%3==1)
                              indp[colindex]=-1;
      }

     // pass++;

}

[ 本帖最后由 〇〇 于 2010-3-10 14:28 编辑 ]

d.rar

3.21 KB, 下载次数: 62

使用道具 举报

回复

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

本版积分规则 发表回复

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