home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 January / Chip_2001-01_cd1.bin / tema / mysql / mysql-3.23.28g-win.exe / DATA1.CAB / Benchmark_Files / bench / test-ATIS < prev    next >
Text File  |  2000-11-22  |  25KB  |  553 lines

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