test-ATIS
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:25k
源码类别:

模拟服务器

开发平台:

C/C++

  1. #!/usr/bin/perl
  2. # Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  3. #
  4. # This library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Library General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2 of the License, or (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. # Library General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Library General Public
  15. # License along with this library; if not, write to the Free
  16. # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  17. # MA 02111-1307, USA
  18. #
  19. # Test of creating the ATIS database and doing many different selects on it
  20. #
  21. # changes made for Oracle compatibility
  22. # - added Oracle to the '' to ' ' translation
  23. # - skip blank lines from the datafiles
  24. # - skip a couple of the tests in Q4 that Oracle doesn't understand
  25. ################### Standard benchmark inits ##############################
  26. use DBI;
  27. use Benchmark;
  28. $opt_loop_count=100; # Run selects this many times
  29. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  30. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!n";
  31. if ($opt_small_test)
  32. {
  33.   $opt_loop_count/=10;
  34. }
  35. print "ATIS table testnn";
  36. ####
  37. ####  Connect and start timeing
  38. ####
  39. $dbh = $server->connect();
  40. $start_time=new Benchmark;
  41. ####
  42. #### Create needed tables
  43. ####
  44. init_data(); # Get table definitions
  45. if (!$opt_skip_create)
  46. {
  47.   print "Creating tablesn";
  48.   $loop_time= new Benchmark;
  49.   for ($ti = 0; $ti <= $#table_names; $ti++)
  50.   {
  51.     my $table_name = $table_names[$ti];
  52.     my $array_ref = $tables[$ti];
  53.     # This may fail if we have no table so do not check answer
  54.     $sth = $dbh->do("drop table $table_name" . $server->{'drop_attr'});
  55.     print "Creating table $table_namen" if ($opt_verbose);
  56.     do_many($dbh,@$array_ref);
  57.   }
  58.   $end_time=new Benchmark;
  59.   print "Time for create_table (" . ($#tables+1) ."): " .
  60.     timestr(timediff($end_time, $loop_time),"all") . "nn";
  61.   if ($opt_fast && defined($server->{vacuum}))
  62.   {
  63.     $server->vacuum(0,$dbh);
  64.   }
  65. ####
  66. #### Insert data
  67. ####
  68.   print "Inserting datan";
  69.   $loop_time= new Benchmark;
  70.   $row_count=0;
  71.   $double_quotes=$server->{'double_quotes'};
  72.   if ($opt_lock_tables)
  73.   {
  74.     @tmp=@table_names; push(@tmp,@extra_names);
  75.     print "LOCK TABLES @tmpn" if ($opt_debug);
  76.     $sth = $dbh->do("LOCK TABLES " . join(" WRITE,", @tmp) . " WRITE") ||
  77.       die $DBI::errstr;
  78.   }
  79.   if ($opt_fast && $server->{'limits'}->{'load_data_infile'})
  80.   {
  81.     for ($ti = 0; $ti <= $#table_names; $ti++)
  82.     {
  83.       my $table_name = $table_names[$ti];
  84.       my $file = "$pwd/Data/ATIS/${table_name}.txt";
  85.       print "$table_name - $filen" if ($opt_debug);
  86.       $row_count += $server->insert_file($table_name,$file,$dbh);
  87.     }
  88.   }
  89.   else
  90.   {
  91.     for ($ti = 0; $ti <= $#table_names; $ti++)
  92.     {
  93.       my $table_name = $table_names[$ti];
  94.       my $array_ref = $tables[$ti];
  95.       my @table = @$array_ref;
  96.       my $insert_start = "insert into $table_name values (";
  97.       open(DATA, "$pwd/Data/ATIS/${table_name}.txt") || die "Can't open text file: $pwd/Data/ATIS/${table_name}.txtn";
  98.       while(<DATA>)
  99.       {
  100. chomp;
  101. next unless ( $_ =~ /w/ ); # skip blank lines
  102. my $command = $insert_start . $_ . ")";
  103.         $command =~ s/''/' '/g if ($opt_server =~ /empress/i || $opt_server =~ /oracle/i);
  104.         $command =~ s/\'//g if ($opt_server =~ /informix/i);
  105. print "$commandn" if ($opt_debug);
  106.         $command =~ s/\'/''/g if ($double_quotes);
  107. $sth = $dbh->do($command) or die "Got error: $DBI::errstr when executing '$command'n";
  108. $row_count++;
  109.       }
  110.     }
  111.     close(DATA);
  112.   }
  113.   if ($opt_lock_tables)
  114.   {
  115.     $dbh->do("UNLOCK TABLES");
  116.   }
  117.   $end_time=new Benchmark;
  118.   print "Time to insert ($row_count): " .
  119.     timestr(timediff($end_time, $loop_time),"all") . "nn";
  120. }
  121. if ($opt_fast && defined($server->{vacuum}))
  122. {
  123.   $server->vacuum(0,$dbh,@table_names);
  124. }
  125. if ($opt_lock_tables)
  126. {
  127.   @tmp=@table_names; push(@tmp,@extra_names);
  128.   $sth = $dbh->do("LOCK TABLES " . join(" READ,", @tmp) . " READ") ||
  129.     die $DBI::errstr;
  130. }
  131. #
  132. # Now the fun begins.  Let's do some simple queries on the result
  133. #
  134. # The query array is defined as:
  135. # query, number of rows in result, 0|1 where 1 means that the query is possible
  136. #
  137. print "Retrieving datan";
  138. @Q1=("select_simple_join",
  139.      "select city.city_name,state.state_name,city.city_code from city,state where city.city_code='MATL' and city.state_code=state.state_code",1,1,
  140.      "select city.city_name,state.state_name,city.city_code from state,city where city.state_code=state.state_code",11,1,
  141.      "select month_name.month_name,day_name.day_name from month_name,day_name where month_name.month_number=day_name.day_code",7,1,
  142.      "select month_name.month_name,day_name.day_name from month_name,day_name where month_name.month_number=day_name.day_code and day_name.day_code >= 4",4,1,
  143.      "select flight.flight_code,aircraft.aircraft_type from flight,aircraft where flight.aircraft_code=aircraft.aircraft_code",579,1,
  144.      );
  145. @Q2=("select_join",
  146.      "select airline.airline_name,aircraft.aircraft_type from aircraft,airline,flight where flight.aircraft_code=aircraft.aircraft_code and flight.airline_code=airline.airline_code",579,1);
  147. @Q21=("select_key_prefix_join",
  148.      "select fare.fare_code from restrict_carrier,airline,fare where restrict_carrier.airline_code=airline.airline_code and fare.restrict_code=restrict_carrier.restrict_code",5692,1,
  149.     );
  150. @Q3=("select_distinct",
  151.      "select distinct category from aircraft",6,1,
  152.      "select distinct from_airport from flight",9,1,
  153.      "select distinct aircraft_code from flight",22,1,
  154.      "select distinct * from fare",534,1,
  155.      "select distinct flight_code from flight_fare",579,1,
  156.      "select distinct flight.flight_code,aircraft.aircraft_type from flight,aircraft where flight.aircraft_code=aircraft.aircraft_code",579,1,
  157.      "select distinct airline.airline_name,aircraft.aircraft_type from aircraft,airline,flight where flight.aircraft_code=aircraft.aircraft_code and flight.airline_code=airline.airline_code",44,$limits->{'join_optimizer'},
  158.      "select distinct airline.airline_name,aircraft.aircraft_type from flight,aircraft,airline where flight.aircraft_code=aircraft.aircraft_code and flight.airline_code=airline.airline_code",44,1,
  159.      );
  160. @Q4=("select_group",
  161.      "select day_name.day_name,day_name.day_code,count(*) from flight_day,day_name where day_name.day_code=flight_day.day_code group by day_name.day_name,day_name.day_code order by day_name.day_code",7,$limits->{'group_functions'},
  162.      "select day_name.day_name,count(*) from flight_day,day_name where day_name.day_code=flight_day.day_code group by day_name.day_name",7,$limits->{'group_functions'},
  163.      "select month_name,day_name from month_name,day_name where month_number=day_code and day_code>3 group by month_name,day_name",4,$limits->{'group_functions'},
  164.      "select day_name.day_name,flight_day.day_code,count(*) from flight_day,day_name where day_name.day_code=flight_day.day_code group by flight_day.day_code,day_name.day_name order by flight_day.day_code",7,$limits->{'group_functions'},
  165.      "select sum(engines) from aircraft",1,$limits->{'group_functions'},
  166.      "select avg(engines) from aircraft",1,$limits->{'group_functions'},
  167.      "select avg(engines) from aircraft where engines>0",1,$limits->{'group_functions'},
  168.      "select count(*),min(pay_load),max(pay_load) from aircraft where pay_load>0",1,$limits->{'group_functions'},
  169.      "select min(flight_code),min(flight_code) from flight",1,$limits->{'group_functions'},
  170.      "select min(from_airport),min(to_airport) from flight",1,$limits->{'group_functions'} && $limits->{'group_func_sql_min_str'},
  171.      "select count(*) from aircraft where pay_load>10000",1,$limits->{'group_functions'},
  172.      "select count(*) from aircraft where pay_load<>0",1,$limits->{'group_functions'},
  173.      "select count(*) from flight where flight_code >= 112793",1,$limits->{'group_functions'},
  174.      "select count(if(pay_load,1,NULL)) from aircraft",1,$limits->{'if'} && $limits->{'group_functions'},
  175.      "select std(engines) from aircraft",1,$limits->{'group_func_extra_std'},
  176.      "SELECT from_airport,to_airport,avg(time_elapsed) FROM flight WHERE from_airport='ATL' AND to_airport='BOS' group by from_airport,to_airport",1,$limits->{'group_functions'},
  177.      "select city_code, avg(ground_fare) from ground_service where ground_fare<>0 group by city_code",11,$limits->{'group_functions'},
  178.      "select count(*), ground_service.city_code from ground_service group by ground_service.city_code",12,$limits->{'group_functions'},
  179.      "select category,count(*) as totalnr from aircraft where engines=2 group by category having totalnr>4",3,$limits->{'group_functions'} && $limits->{'having_with_alias'},
  180.      "select category,count(*) from aircraft where engines=2 group by category having count(*)>4",3,$limits->{'group_functions'} && $limits->{'having_with_group'},
  181.      "select flight_number,range_miles,fare_class FROM aircraft,flight,flight_class WHERE flight.flight_code=flight_class.flight_code AND flight.aircraft_code=aircraft.aircraft_code AND range_miles<>0 AND (stops=1 OR stops=2) GROUP BY flight_number,range_miles,fare_class",150,$limits->{'group_functions'},
  182.      "select distinct from_airport.time_zone_code,to_airport.time_zone_code,(FLOOR(arrival_time/100)*60+MOD(arrival_time,100)-FLOOR(departure_time/100)*60-MOD(departure_time,100)-time_elapsed)/60 AS time_zone_diff FROM flight,airport AS from_airport,airport AS to_airport WHERE flight.from_airport=from_airport.airport_code AND flight.to_airport=to_airport.airport_code GROUP BY from_airport.time_zone_code,to_airport.time_zone_code,arrival_time,departure_time,time_elapsed",21,$limits->{'func_odbc_mod'} && $limits->{'func_odbc_floor'} && $limits->{'group_functions'},
  183.      "select DISTINCT from_airport.time_zone_code,to_airport.time_zone_code,MOD((FLOOR(arrival_time/100)*60+MOD(arrival_time,100)-FLOOR(departure_time/100)*60-MOD(departure_time,100)-time_elapsed)/60+36,24)-12 AS time_zone_diff FROM flight,airport AS from_airport,airport AS to_airport WHERE flight.from_airport=from_airport.airport_code AND flight.to_airport=to_airport.airport_code and MOD((FLOOR(arrival_time/100)*60+MOD(arrival_time,100)-FLOOR(departure_time/100)*60-MOD(departure_time,100)-time_elapsed)/60+36,24)-12 < 10",14,$limits->{'func_odbc_mod'} && $limits->{'func_odbc_floor'} && $limits->{'group_functions'},
  184.      "select from_airport,to_airport,range_miles,time_elapsed FROM aircraft,flight WHERE aircraft.aircraft_code=flight.aircraft_code AND to_airport NOT LIKE from_airport AND range_miles<>0 AND time_elapsed<>0 GROUP BY from_airport,to_airport,range_miles,time_elapsed",409,$limits->{'group_functions'} && $limits->{'like_with_column'},
  185.      "SELECT airport.country_name,state.state_name,city.city_name,airport_service.direction FROM airport_service,state,airport,city WHERE airport_service.city_code=city.city_code AND airport_service.airport_code=airport.airport_code AND state.state_code=airport.state_code AND state.state_code=city.state_code AND airport.state_code=city.state_code AND airport.country_name=city.country_name AND airport.country_name=state.country_name AND city.time_zone_code=airport.time_zone_code GROUP BY airport.country_name,state.state_name,city.city_name,airport_service.direction ORDER BY state_name",11,$limits->{'group_functions'},
  186.      "SELECT airport.country_name,state.state_name,city.city_name,airport_service.direction FROM airport_service,state,airport,city WHERE airport_service.city_code=city.city_code AND airport_service.airport_code=airport.airport_code AND state.state_code=airport.state_code AND state.state_code=city.state_code AND airport.state_code=city.state_code AND airport.country_name=city.country_name AND airport.country_name=state.country_name AND city.time_zone_code=airport.time_zone_code GROUP BY airport.country_name,state.state_name,city.city_name,airport_service.direction ORDER BY state_name DESC",11,$limits->{'group_functions'},
  187.      "SELECT airport.country_name,state.state_name,city.city_name,airport_service.direction FROM airport_service,state,airport,city WHERE airport_service.city_code=city.city_code AND airport_service.airport_code=airport.airport_code AND state.state_code=airport.state_code AND state.state_code=city.state_code AND airport.state_code=city.state_code AND airport.country_name=city.country_name AND airport.country_name=state.country_name AND city.time_zone_code=airport.time_zone_code GROUP BY airport.country_name,state.state_name,city.city_name,airport_service.direction ORDER BY state_name",11,$limits->{'group_functions'},
  188.      "SELECT from_airport,to_airport,fare.fare_class,night,one_way_cost,rnd_trip_cost,class_days FROM compound_class,fare WHERE compound_class.fare_class=fare.fare_class AND one_way_cost <= 825 AND one_way_cost >= 280 AND from_airport='SFO' AND to_airport='DFW' GROUP BY from_airport,to_airport,fare.fare_class,night,one_way_cost,rnd_trip_cost,class_days ORDER BY one_way_cost",10,$limits->{'group_functions'},
  189.      "select engines,category,cruising_speed,from_airport,to_airport FROM aircraft,flight WHERE category='JET' AND ENGINES >= 1 AND aircraft.aircraft_code=flight.aircraft_code AND to_airport NOT LIKE from_airport AND stops>0 GROUP BY engines,category,cruising_speed,from_airport,to_airport ORDER BY engines DESC",29,$limits->{'group_functions'} && $limits->{'like_with_column'},
  190.      );
  191. @Q=(@Q1,@Q2,@Q21,@Q3,@Q4);
  192. foreach $Q (@Q)
  193. {
  194.   $count=$estimated=0;
  195.   $loop_time= new Benchmark;
  196.   for ($i=1 ; $i <= $opt_loop_count; $i++)
  197.   {
  198.     for ($j=1 ; $j < $#$Q ; $j+=3)
  199.     {
  200.       if ($Q->[$j+2])
  201.       { # We can do it with current limits
  202. $count++;
  203. if ($i == 100) # Do something different
  204. {
  205.   if (($row_count=fetch_all_rows($dbh,$server->query($Q->[$j]))) !=
  206.       $Q->[$j+1])
  207.   {
  208.     if ($row_count == undef())
  209.     {
  210.       die "Got error: $DBI::errstr when executing " . $Q->[$j] ."n"."got $row_count instead of $Q->[$j+1] *** n";
  211.     }
  212.     print "Warning: Query '" . $Q->[$j] . "' returned $row_count rows when it should have returned " . $Q->[$j+1] . " rowsn";
  213.   }
  214. }
  215. else
  216. {
  217.   defined(fetch_all_rows($dbh,$server->query($Q->[$j])))
  218.     or die "ERROR: $DBI::errstr executing '$Q->[$j]'n";
  219. }
  220.       }
  221.     }
  222.     $end_time=new Benchmark;
  223.     last if ($estimated=predict_query_time($loop_time,$end_time,$count,$i,
  224.    $opt_loop_count));
  225.     print "Loop $in" if ($opt_verbose);
  226.   }
  227.   if ($count)
  228.   {
  229.     if ($estimated)
  230.     { print "Estimated time"; }
  231.     else
  232.     { print "Time"; }
  233.     print  " for " . $Q->[0] . " ($count): " .
  234.       timestr(timediff($end_time, $loop_time),"all") . "n";
  235.   }
  236. }
  237. print "n";
  238. ####
  239. #### Delete the tables
  240. ####
  241. if (!$opt_skip_delete) # Only used when testing
  242. {
  243.   print "Removing tablesn";
  244.   $loop_time= new Benchmark;
  245.   if ($opt_lock_tables)
  246.   {
  247.     $sth = $dbh->do("UNLOCK TABLES") || die $DBI::errstr;
  248.   }
  249.   for ($ti = 0; $ti <= $#table_names; $ti++)
  250.   {
  251.     my $table_name = $table_names[$ti];
  252.     $sth = $dbh->do("drop table $table_name" . $server->{'drop_attr'});
  253.   }
  254.   $end_time=new Benchmark;
  255.   print "Time to drop_table (" .($#table_names+1) . "): " .
  256.     timestr(timediff($end_time, $loop_time),"all") . "n";
  257. }
  258. if ($opt_fast && defined($server->{vacuum}))
  259. {
  260.   $server->vacuum(0,$dbh);
  261. }
  262. ####
  263. #### End of benchmark
  264. ####
  265. $dbh->disconnect; # close connection
  266. end_benchmark($start_time);
  267. sub init_data
  268. {
  269.   @aircraft=
  270.     $server->create("aircraft",
  271.     ["aircraft_code char(3) NOT NULL",
  272.      "aircraft_type char(64) NOT NULL",
  273.      "engines tinyint(1) NOT NULL",
  274.      "category char(10) NOT NULL",
  275.      "wide_body char(3) NOT NULL",
  276.      "wing_span float(6,2) NOT NULL",
  277.      "length1 float(6,2) NOT NULL",
  278.      "weight integer(7) NOT NULL",
  279.      "capacity smallint(3) NOT NULL",
  280.      "pay_load integer(7) NOT NULL",
  281.      "cruising_speed mediumint(5) NOT NULL",
  282.      "range_miles mediumint(5) NOT NULL",
  283.      "pressurized char(3) NOT NULL"],
  284.     ["PRIMARY KEY (aircraft_code)"]);
  285.   @airline=
  286.     $server->create("airline",
  287.     ["airline_code char(2) NOT NULL",
  288.      "airline_name char(64) NOT NULL",
  289.      "notes char(38) NOT NULL"],
  290.     ["PRIMARY KEY (airline_code)"]);
  291.   @airport=
  292.     $server->create("airport",
  293.     ["airport_code char(3) NOT NULL",
  294.      "airport_name char(40) NOT NULL",
  295.      "location char(36) NOT NULL",
  296.      "state_code char(2) NOT NULL",
  297.      "country_name char(25) NOT NULL",
  298.      "time_zone_code char(3) NOT NULL"],
  299.     ["PRIMARY KEY (airport_code)"]);
  300.   @airport_service=
  301.     $server->create("airport_service",
  302.     ["city_code char(4) NOT NULL",
  303.      "airport_code char(3) NOT NULL",
  304.      "miles_distant float(4,1) NOT NULL",
  305.      "direction char(3) NOT NULL",
  306.      "minutes_distant smallint(3) NOT NULL"],
  307.     ["PRIMARY KEY (city_code, airport_code)"]);
  308.   @city=
  309.     $server->create("city",
  310.     ["city_code char(4) NOT NULL",
  311.      "city_name char(25) NOT NULL",
  312.      "state_code char(2) NOT NULL",
  313.      "country_name char(25) NOT NULL",
  314.      "time_zone_code char(3) NOT NULL"],
  315.     ["PRIMARY KEY (city_code)"]);
  316.   @class_of_service=
  317.     $server->create("class_of_service",
  318.     ["class_code char(2) NOT NULL",
  319.      "rank tinyint(2) NOT NULL",
  320.      "class_description char(80) NOT NULL"],
  321.     ["PRIMARY KEY (class_code)"]);
  322.   @code_description=
  323.     $server->create("code_description",
  324.     ["code char(5) NOT NULL",
  325.      "description char(110) NOT NULL"],
  326.     ["PRIMARY KEY (code)"]);
  327.   @compound_class=
  328.     $server->create("compound_class",
  329.     ["fare_class char(3) NOT NULL",
  330.      "base_class char(2) NOT NULL",
  331.      "class_type char(10) NOT NULL",
  332.      "premium char(3) NOT NULL",
  333.      "economy char(3) NOT NULL",
  334.      "discounted char(3) NOT NULL",
  335.      "night char(3) NOT NULL",
  336.      "season_fare char(4) NOT NULL",
  337.      "class_days char(7) NOT NULL"],
  338.     ["PRIMARY KEY (fare_class)"]);
  339.   @connect_leg=
  340.     $server->create("connect_leg",
  341.     ["connect_code integer(8) NOT NULL",
  342.      "leg_number tinyint(1) NOT NULL",
  343.      "flight_code integer(8) NOT NULL"],
  344.     ["PRIMARY KEY (connect_code, leg_number, flight_code)"]);
  345.   @connection=
  346.     $server->create("fconnection",
  347.     ["connect_code integer(8) NOT NULL",
  348.      "from_airport char(3) NOT NULL",
  349.      "to_airport char(3) NOT NULL",
  350.      "departure_time smallint(4) NOT NULL",
  351.      "arrival_time smallint(4) NOT NULL",
  352.      "flight_days char(7) NOT NULL",
  353.      "stops tinyint(1) NOT NULL",
  354.      "connections tinyint(1) NOT NULL",
  355.      "time_elapsed smallint(4) NOT NULL"],
  356.     ["PRIMARY KEY (connect_code)",
  357.      "INDEX from_airport1 (from_airport)",
  358.      "INDEX to_airport1 (to_airport)"]);
  359.   @day_name=
  360.     $server->create("day_name",
  361.     ["day_code tinyint(1) NOT NULL",
  362.      "day_name char(9) NOT NULL"],
  363.     ["PRIMARY KEY (day_code)"]);
  364.   @dual_carrier=
  365.     $server->create("dual_carrier",
  366.     ["main_airline char(2) NOT NULL",
  367.      "dual_airline char(2) NOT NULL",
  368.      "low_flight smallint(4) NOT NULL",
  369.      "high_flight smallint(4) NOT NULL",
  370.      "fconnection_name char(64) NOT NULL"],
  371.     ["PRIMARY KEY (main_airline, dual_airline, low_flight)",
  372.      "INDEX main_airline1 (main_airline)"]);
  373.   @fare=
  374.     $server->create("fare",
  375.     ["fare_code char(8) NOT NULL",
  376.      "from_airport char(3) NOT NULL",
  377.      "to_airport char(3) NOT NULL",
  378.      "fare_class char(3) NOT NULL",
  379.      "fare_airline char(2) NOT NULL",
  380.      "restrict_code char(5) NOT NULL",
  381.      "one_way_cost float(7,2) NOT NULL",
  382.      "rnd_trip_cost float(8,2) NOT NULL"],
  383.     ["PRIMARY KEY (fare_code)",
  384.      "INDEX from_airport2 (from_airport)",
  385.      "INDEX to_airport2 (to_airport)"]);
  386.   @flight=
  387.     $server->create("flight",
  388.     ["flight_code integer(8) NOT NULL",
  389.      "flight_days char(7) NOT NULL",
  390.      "from_airport char(3) NOT NULL",
  391.      "to_airport char(3) NOT NULL",
  392.      "departure_time smallint(4) NOT NULL",
  393.      "arrival_time smallint(4) NOT NULL",
  394.      "airline_code char(2) NOT NULL",
  395.      "flight_number smallint(4) NOT NULL",
  396.      "class_string char(8) NOT NULL",
  397.      "aircraft_code char(3) NOT NULL",
  398.      "meal_code char(7) NOT NULL",
  399.      "stops tinyint(1) NOT NULL",
  400.      "dual_carrier char(1) NOT NULL",
  401.      "time_elapsed smallint(4) NOT NULL"],
  402.     ["PRIMARY KEY (flight_code)",
  403.      "INDEX from_airport3 (from_airport)",
  404.      "INDEX to_airport3 (to_airport)"]);
  405.   @flight_class=
  406.     $server->create("flight_class",
  407.     ["flight_code integer(8) NOT NULL",
  408.      "fare_class char(3) NOT NULL"],
  409.     ["PRIMARY KEY (flight_code, fare_class)"]);
  410.   @flight_day=
  411.     $server->create("flight_day",
  412.     ["day_mask char(7) NOT NULL",
  413.      "day_code tinyint(1) NOT NULL",
  414.      "day_name char(9) NOT NULL"],
  415.     ["PRIMARY KEY (day_mask, day_code)"]);
  416.   @flight_fare=
  417.     $server->create("flight_fare",
  418.     ["flight_code integer(8) NOT NULL",
  419.      "fare_code char(8) NOT NULL"],
  420.     ["PRIMARY KEY (flight_code, fare_code)"]);
  421.   @food_service=
  422.     $server->create("food_service",
  423.     ["meal_code char(4) NOT NULL",
  424.      "meal_number tinyint(1) NOT NULL",
  425.      "meal_class char(10) NOT NULL",
  426.      "meal_description char(10) NOT NULL"],
  427.     ["PRIMARY KEY (meal_code, meal_number, meal_class)"]);
  428.   @ground_service=
  429.     $server->create("ground_service",
  430.     ["city_code char(4) NOT NULL",
  431.      "airport_code char(3) NOT NULL",
  432.      "transport_code char(1) NOT NULL",
  433.      "ground_fare float(6,2) NOT NULL"],
  434.     ["PRIMARY KEY (city_code, airport_code, transport_code)"]);
  435.   @time_interval=
  436.     $server->create("time_interval",
  437.     ["period char(20) NOT NULL",
  438.      "begin_time smallint(4) NOT NULL",
  439.      "end_time smallint(4) NOT NULL"],
  440.     ["PRIMARY KEY (period, begin_time)"]);
  441.   @month_name=
  442.     $server->create("month_name",
  443.     ["month_number tinyint(2) NOT NULL",
  444.      "month_name char(9) NOT NULL"],
  445.     ["PRIMARY KEY (month_number)"]);
  446.   @restrict_carrier=
  447.     $server->create("restrict_carrier",
  448.     ["restrict_code char(5) NOT NULL",
  449.      "airline_code char(2) NOT NULL"],
  450.     ["PRIMARY KEY (restrict_code, airline_code)"]);
  451.   @restrict_class=
  452.     $server->create("restrict_class",
  453.     ["restrict_code char(5) NOT NULL",
  454.      "ex_fare_class char(12) NOT NULL"],
  455.     ["PRIMARY KEY (restrict_code, ex_fare_class)"]);
  456.   @restriction=
  457.     $server->create("restriction",
  458.     ["restrict_code char(5) NOT NULL",
  459.      "application char(80) NOT NULL",
  460.      "no_discounts char(80) NOT NULL",
  461.      "reserve_ticket smallint(3) NOT NULL",
  462.      "stopovers char(1) NOT NULL",
  463.      "return_min smallint(3) NOT NULL",
  464.      "return_max smallint(3) NOT NULL"],
  465.     ["PRIMARY KEY (restrict_code)"]);
  466.   @state=
  467.     $server->create("state",
  468.     ["state_code char(2) NOT NULL",
  469.      "state_name char(25) NOT NULL",
  470.      "country_name char(25) NOT NULL"],
  471.     ["PRIMARY KEY (state_code)"]);
  472.   @stop=
  473.     $server->create("stop1",
  474.     ["flight_code integer(8) NOT NULL",
  475.      "stop_number tinyint(1) NOT NULL",
  476.      "stop_flight integer(8) NOT NULL"],
  477.     ["PRIMARY KEY (flight_code, stop_number)"]);
  478.   @time_zone=
  479.     $server->create("time_zone",
  480.     ["time_zone_code char(3) NOT NULL",
  481.      "time_zone_name char(32) NOT NULL"],
  482.     ["PRIMARY KEY (time_zone_code, time_zone_name)"]);
  483.   @transport=
  484.     $server->create("transport",
  485.     ["transport_code char(1) NOT NULL",
  486.      "transport_desc char(32) NOT NULL"],
  487.     ["PRIMARY KEY (transport_code)"]);
  488. # Avoid not used warnings
  489.   @tables =
  490.     (@aircraft, @airline, @airport, @airport_service,
  491.      @city, @class_of_service, @code_description,
  492.      @compound_class, @connect_leg, @connection, @day_name,
  493.      @dual_carrier, @fare, @flight, @flight_class, @flight_day,
  494.      @flight_fare, @food_service, @ground_service, @time_interval,
  495.      @month_name,
  496.      @restrict_carrier, @restrict_class, @restriction, @state, @stop,
  497.      @time_zone, @transport);
  498.   @table_names =
  499.     ("aircraft", "airline", "airport", "airport_service",
  500.      "city", "class_of_service", "code_description",
  501.      "compound_class", "connect_leg", "fconnection", "day_name",
  502.      "dual_carrier", "fare", "flight", "flight_class", "flight_day",
  503.      "flight_fare", "food_service", "ground_service", "time_interval",
  504.      "month_name",
  505.      "restrict_carrier", "restrict_class", "restriction", "state", "stop1",
  506.      "time_zone", "transport");
  507. # Alias used in joins
  508.   @extra_names=("airport as from_airport","airport as to_airport");
  509. }