#!/usr/bin/perl $max_session = 5000; $infs_per_session = 140; $max_inf = $infs_per_session * $max_session; @sessions = (1..$max_session); foreach $i (reverse 0 .. @sessions ) { #remove every 13th entry if (!($i % 13)) { splice(@sessions, $i, 1); } } @infs = (1..$max_inf); foreach $i (reverse 0 .. @infs ) { #remove every 11th entry if (!($i % 11)) { splice(@infs, $i, 1); } } foreach $i (0..@infs) { $inf_sess{$i} = $sessions[$i % @sessions]; } @action = (0..9); foreach $i (@action) { $act{$i} = (($i + 1)% 2) ? "'GOOD'" : "'BAD'"; push(@good_action, $i) if (($i + 1)% 2) ; } open(SESSION, "> session.dat"); print SESSION join("\n", @sessions),"\n"; close SESSION; open(INF, "> inf.dat"); foreach $a (keys %inf_sess) { print INF "$a,$inf_sess{$a},$action[$a % @action]\n"; } close INF; open(ACTION, "> action.dat"); foreach $a (sort {$a <=> $b} keys %act) { print ACTION "$a,$act{$a}\n"; } close ACTION ; open(SCRIPT, "> inf_sess_act.sql"); print SCRIPT "USE TEST;\n"; print SCRIPT "DROP TABLE IF EXISTS sess;\n"; print SCRIPT "DROP TABLE IF EXISTS inf;\n"; print SCRIPT "DROP TABLE IF EXISTS act;\n"; print SCRIPT "create table sess (id integer, PRIMARY KEY (id));\n"; print SCRIPT "create table inf (id integer, session_id integer, action_id integer,PRIMARY KEY (id));\n"; print SCRIPT "create table act (id integer, code varchar(20), PRIMARY KEY (id));\n"; print SCRIPT "LOAD DATA LOCAL INFILE 'session.dat' INTO TABLE sess FIELDS TERMINATED BY ',';\n"; print SCRIPT "LOAD DATA LOCAL INFILE 'inf.dat' INTO TABLE inf FIELDS TERMINATED BY ',';\n"; print SCRIPT "LOAD DATA LOCAL INFILE 'action.dat' INTO TABLE act FIELDS TERMINATED BY ',' ENCLOSED BY \"'\";\n"; print SCRIPT "SELECT SYSDATE() FROM DUAL;\n"; print SCRIPT "SELECT count(*) FROM sess s, inf i WHERE s.id = i.session_id AND i.action_id IN (SELECT id FROM act WHERE code = 'GOOD');\n"; print SCRIPT "SELECT SYSDATE() FROM DUAL;\n"; print SCRIPT "SELECT count(*) FROM sess s, inf i WHERE s.id = i.session_id AND i.action_id IN (" . join(",", @good_action) . ");\n"; print SCRIPT "SELECT SYSDATE() FROM DUAL;\n"; close SCRIPT ;