|
原帖由 newkid 于 2009-3-3 05:37 发表 ![]()
在你#272贴的帮助下把程序看懂了。现在我只需要你的数据结构作最后的确认。
你这个程序只能发布一天的吗?最好能把需求改为发布一个日期区间的。数据量越大越能体现SQL的优势。
实际应用中重复发布的情况多不多?如果不多的话我就只考虑INSERT就够了,用不上MERGE。
程序调通了,原来那个程序还是有点错误的,语法错误,逻辑基本还是对的。
发布一下当日的,由于今天夜里已发布过,失败的,由于有了dummy_update,仅用:(原来要好几分钟呢)
tuxticket@jgbticket:~/test> time ./xwfb.sh
real 0m2.290s
user 0m0.268s
sys 0m0.124s
发布明天的,-D+1就是明天,成功5156个席位。原来6秒,不用DAU,也没有bind。
tuxticket@jgbticket:~/test> time ./xwfb.sh -D+1
real 0m1.656s
user 0m0.184s
sys 0m0.104s
- 5 xwfbDAU:2930 03/06 10:50'17 xwfb gettrain:train_no=H1,beg_date=2008.02.01,end_date=2099.12.31,jobday=2009-03-17,i_item=1
- 5 xwfbDAU:2930 03/06 10:50'17 bind_ins:sth=0,stmt=INSERT INTO TICKET.SEAT (start_date,beg_station,train_no,run_train,on_date,carno,seat_type,seat_no,end_station,shortest_station,purpose,gride,pro,flag,used_dev,used_uid,used_time) VALUES (to_date(:1,'YYYY-MM-DD'), :2, :3, :4,to_date(:5,'YYYY-MM-DD HH24:MI'), :6, :7, :8, :9, :10, :11, :12, :13, :14, :15, :16,to_date(:17,'YYYY-MM-DD HH24:MI:SS'))
- 2 xwfbDAU:2930 03/06 10:50'17 train=2009-03-17;H1,carno=0,beg_station=YZHP,end_station=5,remant=30
- 5 xwfbDAU:2930 03/06 10:50'17 bind_prepare:cursor=1,SELECT to_char(on_date,'YYYY-MM-DD') on_date,beg_station,run_train,carno,seat_type,purpose,end_station,amoung FROM TICKET.SEAT_REMANT WHERE on_date=to_date(:1,'YYYY-MM-DD') AND beg_station=:2 AND run_train=:3 AND carno=:4 AND seat_type=:5 AND purpose=:6 AND end_station=:7 for update
- 5 xwfbDAU:2930 03/06 10:50'17 bind_ins:sth=2,stmt=INSERT INTO TICKET.SEAT_REMANT (on_date,beg_station,run_train,carno,seat_type,purpose,end_station,amoung) VALUES (to_date(:1,'YYYY-MM-DD'), :2, :3, :4, :5, :6, :7, :8)
- 2 xwfbDAU:2930 03/06 10:50'17 train=2009-03-17;H1,carno=0,beg_station=YLHP,end_station=5,remant=30
- 5 xwfbDAU:2930 03/06 10:50'17 bind_ins:sth=3,stmt=INSERT INTO TICKET.SEAT (start_date,beg_station,train_no,run_train,on_date,carno,seat_type,seat_no,end_station,shortest_station,purpose,gride,pro,flag,used_dev,used_uid,used_time) VALUES (to_date(:1,'YYYY-MM-DD'), :2, :3, :4,to_date(:5,'YYYY-MM-DD HH24:MI'), :6, :7, :8, :9, :10, :11, :12, :13, :14, :15, :16,to_date(:17,'YYYY-MM-DD HH24:MI:SS'))
- 2 xwfbDAU:2930 03/06 10:50'17 mkxw train=2009-03-17:H1,beg_station=BNHP,end_station=5,carno=1,remant=120
- 5 xwfbDAU:2930 03/06 10:50'17 bind_prepare:cursor=4,SELECT to_char(on_date,'YYYY-MM-DD') on_date,beg_station,run_train,carno,seat_type,purpose,end_station,amoung FROM TICKET.SEAT_REMANT WHERE on_date=to_date(:1,'YYYY-MM-DD') AND beg_station=:2 AND run_train=:3 AND carno=:4 AND seat_type=:5 AND purpose=:6 AND end_station=:7 for update
- 5 xwfbDAU:2930 03/06 10:50'17 bind_ins:sth=5,stmt=INSERT INTO TICKET.SEAT_REMANT (on_date,beg_station,run_train,carno,seat_type,purpose,end_station,amoung) VALUES (to_date(:1,'YYYY-MM-DD'), :2, :3, :4, :5, :6, :7, :8)
- 5 xwfbDAU:2930 03/06 10:50'17 bind_update:bind=4,sth=6,stmt=UPDATE TICKET.PRE_SEAT_INDEX SET distribute_time=to_date(:1,'YYYY-MM-DD HH24:MI:SS') WHERE train_no=:2 AND item=:3 AND end_date=to_date(:4,'YYYY-MM-DD'),
- 2 xwfbDAU:2930 03/06 10:50'19 totalnum=5156
- 补充语句:
- 2 xwfb:21149 03/04 02:00'01 stmt=select Train_no,to_char(beg_date,'YYYY-MM-DD') beg_date,to_char(end_date,'YYYY-MM-DD') end_date,start_station,end_station,station_num,total_distance,start_time,iterms,cycle,gride,price_mode,discount_mode,days,flag,owner,note from TICKET.train where flag=0 and end_date >= to_date('2009-03-04','YYYY-MM-DD')
- 5 xwfb:21149 03/04 02:00'01 xwfb gettrain:Train_no=H1,beg_date=2008.02.01,end_date=2099.12.31,jobday=2009-03-14,i_item=1
- 5 xwfb:21149 03/04 02:00'01 查找停靠站表 stmt=select Train_no,run_Train_no,sequence,to_char(beg_date,'YYYY-MM-DD') beg_date,to_char(end_date,'YYYY-MM-DD') end_date,station_code,distance,running_time,stop_time,over,flag from TICKET.stop_station where train_no='H1' and beg_date <= to_date('2009-03-14','YYYY-MM-DD') and end_date >= to_date('2009-03-14','YYYY-MM-DD') and over>0 ,ret=2
- 5 xwfbDAU:3715 03/06 13:56'52 xwfb:SELECT train_no,item,to_char(beg_date,'YYYY-MM-DD') beg_date,to_char(end_date,'YYYY-MM-DD') end_date,flag,to_char(distribute_time,'YYYY-MM-DD HH24:MI:SS') distribute_time,note FROM TICKET.PRE_SEAT_INDEX WHERE train_no=:1 AND item=:2 AND beg_date <= to_date(:3,'YYYY-MM-DD') AND end_date >= to_date(:4,'YYYY-MM-DD') AND flag=0
- 那个pre_seat,就是: where pre_id=:pre_id
复制代码- //* default with not null */
- /* 母表分为母表索引和母表两部分如下:*/
- drop table pre_seat_index;
- create table pre_seat_index ( -- 母表索引
- Train_no varchar2(12), -- 全车次
- item char(1) default '1',-- 组号,一般='1'
- beg_date date, -- 有效起始日期 YYYY-MM-DD
- end_date date, -- 有效结束日期 YYYY-MM-DD
- flag number(1), --* 0:有效,其它:无效
- distribute_time date null, -- 最后发布时间 YYYY-MM-DD HH24:MI:SS
- note varchar(20),
- primary key (Train_no,item,end_date)
- );
- drop table pre_seat;
- create table pre_seat ( -- 母表
- Pre_ID varchar2(23), -- 索引,由pre_seat_index里的字段拼凑而来:
- -- Train_no:itam:beg_date(YYYYMMDD)
- Carno number(2), -- 车厢号,不分车厢的票车厢号=0
- seat_type number(4), --席别,0=无号
- beg_seatno number(3), -- 开始席号
- end_seatno number(3),-- 结束席号
- beg_station number(3), -- 上车站
- end_station number(3), -- 最远站
- shortest_station number(3), -- 限售以远
- purpose number(9), -- 用途
- gride varchar2(50), -- 事由码,新空调直达特快等。
- primary key (Pre_ID,Carno,beg_seatno,beg_station)
- );
- drop table seat;
- create table seat ( /* 席位表 */
- start_date date, /* 始发日期 YYYY-MM-DD*/
- beg_station varchar2(4), /* 上车站略码 */
- Train_no varchar2(12), /* 全车次 */
- run_train varchar2(6), /* 运行车次 */
- on_date date, /* 上车日期 YYYY-MM-DD HH24:MI*/
- Carno number(2), /* 车厢号,不分车厢的票车厢号=0 */
- seat_type number(2), /*席别,0=无号*/
- seat_no number(3), /* 席位号 */
- end_station number(3), /* 顺号,售前是最远站,售后改为下车站 */
- shortest_station number(3), /* 顺号,限售以远 */
- purpose number(9), /* 用途 */
- gride varchar2(50), -- 事由码,新空调直达特快等。
- pro char(5) null, -- 席位属性码(靠窗,走道等
- flag number(1), /* 标志:0正常,1占用,2已售,3暂不可用,-1禁售 */
- used_dev varchar2(16) null, /* 最后操作终端 */
- used_uid varchar2(16) null, /* 最后操作人 */
- used_time date null, /* 最后操作时间 YYYY-MM-DD HH24:MI:SS */
- primary key(start_date,beg_station,Train_no,Carno,
- seat_no,seat_type)
- );
- -- create index seat_idx on seat(beg_station,on_date,run_train,end_station);
- create index seat_release on seat(flag,used_time); /* 释放占用 */
- drop table seat_remant;
- create table seat_remant ( /* 存量表 */
- on_date date, /* 上车日期 */
- beg_station varchar2(4), /* 上车站略码 */
- run_train varchar2(12), /* 运行车次 */
- Carno number(2), /* 车厢号,不分车厢的票车厢号=0 */
- seat_type number(4), /*席别,0=无号*/
- purpose number(9), /* 用途 */
- end_station number(3), /* 最远站 */
- amoung number(3), /* 数量 */
- primary key(on_date,beg_station,run_train,Carno,
- seat_type,purpose,end_station)
- );
- drop table station;
- create table station (
- station_code varchar2(4),
- station_name varchar2(20),
- beg_date date,
- end_date date,
- abbreviation varchar2(6) null,
- unit varchar2(16) null,
- line varchar2(8) null,
- area varchar2(16) null,
- spell varchar2(20),
- station_type varchar2(2) null,
- statis_code number(10) null,
- flag number(1), /* 0:有效,其它无效 */
- ac_fee number(2), /* 车站空调费 */
- x number(8,3) , /* 经度 */
- y number(8,3), /* 纬度 */
- primary key (station_code,end_date)
- );
- create index station_py on station(spell);
- create index station_name on station(station_name);
- drop table Train;
- create table Train ( /* 车次表 */
- Train_no varchar2(12), /* 全车次 */
- beg_date date, /* 有效起始日 */
- end_date date, /* 有效截止日 */
- start_station varchar2(4), /* 始发站 */
- end_station varchar2(4), /* 终到站 */
- station_num number(3), /* 停站数 */
- total_distance number(6), /* 总里程 */
- start_time number(4), /* 发车时间,分钟数 */
- iterms number(2), /* 席位组数 */
- cycle varchar2(31), /* 计算席位周期 */
- gride char(5), /* 等级,普、快、特快等 */
- price_mode number(6), /* 票价规则 */
- discount_mode number(6), /* 折扣规则 */
- days number(3) null, /* 席位发行天数 */
- flag number(1), /* 0可用,1不可用 */
- owner varchar2(16) null, /* 担当单位 */
- note varchar2(50) null, /* 备注 */
- primary key (Train_no,end_date)
- );
- drop table stop_station;
- create table stop_station (
- Train_no varchar2(12), /* 全车次 */
- run_Train_no varchar2(6), /* 运行车次 */
- sequence number(3), /* 顺号 */
- beg_date date, /* 有效起始日期 */
- end_date date, /* 有效结束日期 */
- station_code varchar2(4), /* 车站代码 */
- distance number(6), /* 自始发站里程 */
- running_time number(6), /* 自始发站运行分钟数 */
- stop_time number(2), /* 停靠分钟数 */
- over number(4) null, /* 超员数(本站可售无号数) */
- flag number(1), /* 0可用,1封站 */
- primary key (Train_no,sequence,end_date )
- );
- create index s_station_q on stop_station (Train_no,station_code,end_date);
- create index stop_station_idx on stop_station(station_code,run_Train_no,end_date);
复制代码
[ 本帖最后由 yulihua49 于 2009-3-6 17:07 编辑 ] |
|