home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 March / PCWorld_2003-03_cd.bin / Software / Vyzkuste / phptriad / phptriad2-2-1.exe / mysql / bench / test-ATIS < prev    next >
Text File  |  2001-12-29  |  25KB  |  555 lines

  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.  
  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" . $server->{'drop_attr'});
  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.  
  172. @Q21=("select_key_prefix_join",
  173.      "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,
  174.     );
  175.  
  176. @Q3=("select_distinct",
  177.      "select distinct category from aircraft",6,1,
  178.      "select distinct from_airport from flight",9,1,
  179.      "select distinct aircraft_code from flight",22,1,
  180.      "select distinct * from fare",534,1,
  181.      "select distinct flight_code from flight_fare",579,1,
  182.      "select distinct flight.flight_code,aircraft.aircraft_type from flight,aircraft where flight.aircraft_code=aircraft.aircraft_code",579,1,
  183.      "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'},
  184.      "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,
  185.      );
  186.  
  187. @Q4=("select_group",
  188.      "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'},
  189.      "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'},
  190.      "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'},
  191.      "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'},
  192.      "select sum(engines) from aircraft",1,$limits->{'group_functions'},
  193.      "select avg(engines) from aircraft",1,$limits->{'group_functions'},
  194.      "select avg(engines) from aircraft where engines>0",1,$limits->{'group_functions'},
  195.      "select count(*),min(pay_load),max(pay_load) from aircraft where pay_load>0",1,$limits->{'group_functions'},
  196.      "select min(flight_code),min(flight_code) from flight",1,$limits->{'group_functions'},
  197.      "select min(from_airport),min(to_airport) from flight",1,$limits->{'group_functions'} && $limits->{'group_func_sql_min_str'},
  198.      "select count(*) from aircraft where pay_load>10000",1,$limits->{'group_functions'},
  199.      "select count(*) from aircraft where pay_load<>0",1,$limits->{'group_functions'},
  200.      "select count(*) from flight where flight_code >= 112793",1,$limits->{'group_functions'},
  201.      "select count(if(pay_load,1,NULL)) from aircraft",1,$limits->{'if'} && $limits->{'group_functions'},
  202.      "select std(engines) from aircraft",1,$limits->{'group_func_extra_std'},
  203.      "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'},
  204.      "select city_code, avg(ground_fare) from ground_service where ground_fare<>0 group by city_code",11,$limits->{'group_functions'},
  205.      "select count(*), ground_service.city_code from ground_service group by ground_service.city_code",12,$limits->{'group_functions'},
  206.      "select category,count(*) as totalnr from aircraft where engines=2 group by category having totalnr>4",3,$limits->{'group_functions'} && $limits->{'having_with_alias'},
  207.      "select category,count(*) from aircraft where engines=2 group by category having count(*)>4",3,$limits->{'group_functions'} && $limits->{'having_with_group'},
  208.      "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'},
  209.      "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'},
  210.      "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'},
  211.      "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'},
  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 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'},
  214.      "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'},
  215.      "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'},
  216.      "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'},
  217.      );
  218.  
  219. @Q=(\@Q1,\@Q2,\@Q21,\@Q3,\@Q4);
  220.  
  221.  
  222. foreach $Q (@Q)
  223. {
  224.   $count=$estimated=0;
  225.   $loop_time= new Benchmark;
  226.   for ($i=1 ; $i <= $opt_loop_count; $i++)
  227.   {
  228.     for ($j=1 ; $j < $#$Q ; $j+=3)
  229.     {
  230.       if ($Q->[$j+2])
  231.       {                # We can do it with current limits
  232.     $count++;
  233.     if ($i == 100)        # Do something different
  234.     {
  235.       if (($row_count=fetch_all_rows($dbh,$server->query($Q->[$j]))) !=
  236.           $Q->[$j+1])
  237.       {
  238.         if ($row_count == undef())
  239.         {
  240.           die "Got error: $DBI::errstr when executing " . $Q->[$j] ."\n"."got $row_count instead of $Q->[$j+1] *** \n";
  241.         }
  242.         print "Warning: Query '" . $Q->[$j] . "' returned $row_count rows when it should have returned " . $Q->[$j+1] . " rows\n";
  243.       }
  244.     }
  245.     else
  246.     {
  247.       defined(fetch_all_rows($dbh,$server->query($Q->[$j])))
  248.         or die "ERROR: $DBI::errstr executing '$Q->[$j]'\n";
  249.     }
  250.       }
  251.     }
  252.     $end_time=new Benchmark;
  253.     last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$i,
  254.                        $opt_loop_count));
  255.     print "Loop $i\n" if ($opt_verbose);
  256.   }
  257.   if ($count)
  258.   {
  259.     if ($estimated)
  260.     { print "Estimated time"; }
  261.     else
  262.     { print "Time"; }
  263.     print  " for " . $Q->[0] . " ($count): " .
  264.       timestr(timediff($end_time, $loop_time),"all") . "\n";
  265.   }
  266. }
  267.  
  268. print "\n";
  269.  
  270. ####
  271. #### Delete the tables
  272. ####
  273.  
  274. if (!$opt_skip_delete)                # Only used when testing
  275. {
  276.   print "Removing tables\n";
  277.   $loop_time= new Benchmark;
  278.   if ($opt_lock_tables)
  279.   {
  280.     $sth = $dbh->do("UNLOCK TABLES") || die $DBI::errstr;
  281.   }
  282.   for ($ti = 0; $ti <= $#table_names; $ti++)
  283.   {
  284.     my $table_name = $table_names[$ti];
  285.     $sth = $dbh->do("drop table $table_name" . $server->{'drop_attr'});
  286.   }
  287.  
  288.   $end_time=new Benchmark;
  289.   print "Time to drop_table (" .($#table_names+1) . "): " .
  290.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  291. }
  292.  
  293. if ($opt_fast && defined($server->{vacuum}))
  294. {
  295.   $server->vacuum(0,\$dbh);
  296. }
  297.  
  298. ####
  299. #### End of benchmark
  300. ####
  301.  
  302. $dbh->disconnect;                # close connection
  303.  
  304. end_benchmark($start_time);
  305.  
  306.  
  307. sub init_data
  308. {
  309.   @aircraft=
  310.     $server->create("aircraft",
  311.             ["aircraft_code char(3) NOT NULL",
  312.              "aircraft_type char(64) NOT NULL",
  313.              "engines tinyint(1) NOT NULL",
  314.              "category char(10) NOT NULL",
  315.              "wide_body char(3) NOT NULL",
  316.              "wing_span float(6,2) NOT NULL",
  317.              "length1 float(6,2) NOT NULL",
  318.              "weight integer(7) NOT NULL",
  319.              "capacity smallint(3) NOT NULL",
  320.              "pay_load integer(7) NOT NULL",
  321.              "cruising_speed mediumint(5) NOT NULL",
  322.              "range_miles mediumint(5) NOT NULL",
  323.              "pressurized char(3) NOT NULL"],
  324.             ["PRIMARY KEY (aircraft_code)"]);
  325.   @airline=
  326.     $server->create("airline",
  327.             ["airline_code char(2) NOT NULL",
  328.              "airline_name char(64) NOT NULL",
  329.              "notes char(38) NOT NULL"],
  330.             ["PRIMARY KEY (airline_code)"]);
  331.   @airport=
  332.     $server->create("airport",
  333.             ["airport_code char(3) NOT NULL",
  334.              "airport_name char(40) NOT NULL",
  335.              "location char(36) NOT NULL",
  336.              "state_code char(2) NOT NULL",
  337.              "country_name char(25) NOT NULL",
  338.              "time_zone_code char(3) NOT NULL"],
  339.             ["PRIMARY KEY (airport_code)"]);
  340.   @airport_service=
  341.     $server->create("airport_service",
  342.             ["city_code char(4) NOT NULL",
  343.              "airport_code char(3) NOT NULL",
  344.              "miles_distant float(4,1) NOT NULL",
  345.              "direction char(3) NOT NULL",
  346.              "minutes_distant smallint(3) NOT NULL"],
  347.             ["PRIMARY KEY (city_code, airport_code)"]);
  348.   @city=
  349.     $server->create("city",
  350.             ["city_code char(4) NOT NULL",
  351.              "city_name char(25) NOT NULL",
  352.              "state_code char(2) NOT NULL",
  353.              "country_name char(25) NOT NULL",
  354.              "time_zone_code char(3) NOT NULL"],
  355.             ["PRIMARY KEY (city_code)"]);
  356.   @class_of_service=
  357.     $server->create("class_of_service",
  358.             ["class_code char(2) NOT NULL",
  359.              "rank tinyint(2) NOT NULL",
  360.              "class_description char(80) NOT NULL"],
  361.             ["PRIMARY KEY (class_code)"]);
  362.   @code_description=
  363.     $server->create("code_description",
  364.             ["code char(5) NOT NULL",
  365.              "description char(110) NOT NULL"],
  366.             ["PRIMARY KEY (code)"]);
  367.   @compound_class=
  368.     $server->create("compound_class",
  369.             ["fare_class char(3) NOT NULL",
  370.              "base_class char(2) NOT NULL",
  371.              "class_type char(10) NOT NULL",
  372.              "premium char(3) NOT NULL",
  373.              "economy char(3) NOT NULL",
  374.              "discounted char(3) NOT NULL",
  375.              "night char(3) NOT NULL",
  376.              "season_fare char(4) NOT NULL",
  377.              "class_days char(7) NOT NULL"],
  378.             ["PRIMARY KEY (fare_class)"]);
  379.   @connect_leg=
  380.     $server->create("connect_leg",
  381.             ["connect_code integer(8) NOT NULL",
  382.              "leg_number tinyint(1) NOT NULL",
  383.              "flight_code integer(8) NOT NULL"],
  384.             ["PRIMARY KEY (connect_code, leg_number, flight_code)"]);
  385.   @connection=
  386.     $server->create("fconnection",
  387.             ["connect_code integer(8) NOT NULL",
  388.              "from_airport char(3) NOT NULL",
  389.              "to_airport char(3) NOT NULL",
  390.              "departure_time smallint(4) NOT NULL",
  391.              "arrival_time smallint(4) NOT NULL",
  392.              "flight_days char(7) NOT NULL",
  393.              "stops tinyint(1) NOT NULL",
  394.              "connections tinyint(1) NOT NULL",
  395.              "time_elapsed smallint(4) NOT NULL"],
  396.             ["PRIMARY KEY (connect_code)",
  397.              "INDEX from_airport1 (from_airport)",
  398.              "INDEX to_airport1 (to_airport)"]);
  399.   @day_name=
  400.     $server->create("day_name",
  401.             ["day_code tinyint(1) NOT NULL",
  402.              "day_name char(9) NOT NULL"],
  403.             ["PRIMARY KEY (day_code)"]);
  404.   @dual_carrier=
  405.     $server->create("dual_carrier",
  406.             ["main_airline char(2) NOT NULL",
  407.              "dual_airline char(2) NOT NULL",
  408.              "low_flight smallint(4) NOT NULL",
  409.              "high_flight smallint(4) NOT NULL",
  410.              "fconnection_name char(64) NOT NULL"],
  411.             ["PRIMARY KEY (main_airline, dual_airline, low_flight)",
  412.              "INDEX main_airline1 (main_airline)"]);
  413.  
  414.   @fare=
  415.     $server->create("fare",
  416.             ["fare_code char(8) NOT NULL",
  417.              "from_airport char(3) NOT NULL",
  418.              "to_airport char(3) NOT NULL",
  419.              "fare_class char(3) NOT NULL",
  420.              "fare_airline char(2) NOT NULL",
  421.              "restrict_code char(5) NOT NULL",
  422.              "one_way_cost float(7,2) NOT NULL",
  423.              "rnd_trip_cost float(8,2) NOT NULL"],
  424.             ["PRIMARY KEY (fare_code)",
  425.              "INDEX from_airport2 (from_airport)",
  426.              "INDEX to_airport2 (to_airport)"]);
  427.   @flight=
  428.     $server->create("flight",
  429.             ["flight_code integer(8) NOT NULL",
  430.              "flight_days char(7) NOT NULL",
  431.              "from_airport char(3) NOT NULL",
  432.              "to_airport char(3) NOT NULL",
  433.              "departure_time smallint(4) NOT NULL",
  434.              "arrival_time smallint(4) NOT NULL",
  435.              "airline_code char(2) NOT NULL",
  436.              "flight_number smallint(4) NOT NULL",
  437.              "class_string char(8) NOT NULL",
  438.              "aircraft_code char(3) NOT NULL",
  439.              "meal_code char(7) NOT NULL",
  440.              "stops tinyint(1) NOT NULL",
  441.              "dual_carrier char(1) NOT NULL",
  442.              "time_elapsed smallint(4) NOT NULL"],
  443.             ["PRIMARY KEY (flight_code)",
  444.              "INDEX from_airport3 (from_airport)",
  445.              "INDEX to_airport3 (to_airport)"]);
  446.   @flight_class=
  447.     $server->create("flight_class",
  448.             ["flight_code integer(8) NOT NULL",
  449.              "fare_class char(3) NOT NULL"],
  450.             ["PRIMARY KEY (flight_code, fare_class)"]);
  451.   @flight_day=
  452.     $server->create("flight_day",
  453.             ["day_mask char(7) NOT NULL",
  454.              "day_code tinyint(1) NOT NULL",
  455.              "day_name char(9) NOT NULL"],
  456.             ["PRIMARY KEY (day_mask, day_code)"]);
  457.   @flight_fare=
  458.     $server->create("flight_fare",
  459.             ["flight_code integer(8) NOT NULL",
  460.              "fare_code char(8) NOT NULL"],
  461.             ["PRIMARY KEY (flight_code, fare_code)"]);
  462.   @food_service=
  463.     $server->create("food_service",
  464.             ["meal_code char(4) NOT NULL",
  465.              "meal_number tinyint(1) NOT NULL",
  466.              "meal_class char(10) NOT NULL",
  467.              "meal_description char(10) NOT NULL"],
  468.             ["PRIMARY KEY (meal_code, meal_number, meal_class)"]);
  469.   @ground_service=
  470.     $server->create("ground_service",
  471.             ["city_code char(4) NOT NULL",
  472.              "airport_code char(3) NOT NULL",
  473.              "transport_code char(1) NOT NULL",
  474.              "ground_fare float(6,2) NOT NULL"],
  475.             ["PRIMARY KEY (city_code, airport_code, transport_code)"]);
  476.   @time_interval=
  477.     $server->create("time_interval",
  478.             ["period char(20) NOT NULL",
  479.              "begin_time smallint(4) NOT NULL",
  480.              "end_time smallint(4) NOT NULL"],
  481.             ["PRIMARY KEY (period, begin_time)"]);
  482.   @month_name=
  483.     $server->create("month_name",
  484.             ["month_number tinyint(2) NOT NULL",
  485.              "month_name char(9) NOT NULL"],
  486.             ["PRIMARY KEY (month_number)"]);
  487.   @restrict_carrier=
  488.     $server->create("restrict_carrier",
  489.             ["restrict_code char(5) NOT NULL",
  490.              "airline_code char(2) NOT NULL"],
  491.             ["PRIMARY KEY (restrict_code, airline_code)"]);
  492.   @restrict_class=
  493.     $server->create("restrict_class",
  494.             ["restrict_code char(5) NOT NULL",
  495.              "ex_fare_class char(12) NOT NULL"],
  496.             ["PRIMARY KEY (restrict_code, ex_fare_class)"]);
  497.   @restriction=
  498.     $server->create("restriction",
  499.             ["restrict_code char(5) NOT NULL",
  500.              "application char(80) NOT NULL",
  501.              "no_discounts char(80) NOT NULL",
  502.              "reserve_ticket smallint(3) NOT NULL",
  503.              "stopovers char(1) NOT NULL",
  504.              "return_min smallint(3) NOT NULL",
  505.              "return_max smallint(3) NOT NULL"],
  506.             ["PRIMARY KEY (restrict_code)"]);
  507.   @state=
  508.     $server->create("state",
  509.             ["state_code char(2) NOT NULL",
  510.              "state_name char(25) NOT NULL",
  511.              "country_name char(25) NOT NULL"],
  512.             ["PRIMARY KEY (state_code)"]);
  513.   @stop=
  514.     $server->create("stop1",
  515.             ["flight_code integer(8) NOT NULL",
  516.              "stop_number tinyint(1) NOT NULL",
  517.              "stop_flight integer(8) NOT NULL"],
  518.             ["PRIMARY KEY (flight_code, stop_number)"]);
  519.   @time_zone=
  520.     $server->create("time_zone",
  521.             ["time_zone_code char(3) NOT NULL",
  522.              "time_zone_name char(32) NOT NULL"],
  523.             ["PRIMARY KEY (time_zone_code, time_zone_name)"]);
  524.   @transport=
  525.     $server->create("transport",
  526.             ["transport_code char(1) NOT NULL",
  527.              "transport_desc char(32) NOT NULL"],
  528.             ["PRIMARY KEY (transport_code)"]);
  529.  
  530. # Avoid not used warnings
  531.  
  532.   @tables =
  533.     (\@aircraft, \@airline, \@airport, \@airport_service,
  534.      \@city, \@class_of_service, \@code_description,
  535.      \@compound_class, \@connect_leg, \@connection, \@day_name,
  536.      \@dual_carrier, \@fare, \@flight, \@flight_class, \@flight_day,
  537.      \@flight_fare, \@food_service, \@ground_service, \@time_interval,
  538.      \@month_name,
  539.      \@restrict_carrier, \@restrict_class, \@restriction, \@state, \@stop,
  540.      \@time_zone, \@transport);
  541.  
  542.   @table_names =
  543.     ("aircraft", "airline", "airport", "airport_service",
  544.      "city", "class_of_service", "code_description",
  545.      "compound_class", "connect_leg", "fconnection", "day_name",
  546.      "dual_carrier", "fare", "flight", "flight_class", "flight_day",
  547.      "flight_fare", "food_service", "ground_service", "time_interval",
  548.      "month_name",
  549.      "restrict_carrier", "restrict_class", "restriction", "state", "stop1",
  550.      "time_zone", "transport");
  551.  
  552. # Alias used in joins
  553.   @extra_names=("airport as from_airport","airport as to_airport");
  554. }
  555.