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