$query="select distinct * from workers where workers.department_id=departments.id and departments.title='пилоты' and workers.id=medicals.worker_id and workers.age>=$age1 and workers.age<=$age2 and medicals.year=$year and workers.salary>=$salary1 and workers.salary<=$salary2";
if($med==on) $query .= " and medicals.result=1";
else $query .= " and medicals.result=0";
if($sex==male) $query .= " and workers.sex='м'";
elseif($sex==female) $query .= " and workers.sex='ж'";
$query="select distinct * from planes where planes.num_races>=$races1 and planes.num_races<=$races2 and shedule.time_from>'$time' and shedule.date_from>=current_date and shedule.plane_id=planes.id and planes.entry_to_airport<='$date2' and planes.entry_to_airport>='$date1'";
if($priv!='') $query .= " and planes.private='$priv'";
if($key==1)
{
$query="select distinct * from planes where planes.num_races>=$races1 and planes.num_races<=$races2 and current_date-planes.data_made>=$plane_age*365 and service.date>='$serv_date1' and service.date<='$serv_date2' and service.type_service_id=type_service.id and planes.id=service.plane_id";
if($type==remont) $query .= " and type_service.type='Ремонт'";
else $query .= " and type_service.type='Техосмотр'";
}
else $query="select distinct * from planes where planes.num_races>=$races1 and planes.num_races<=$races2 and current_date-planes.data_made>=$plane_age*365 and $num_serv<=(select count(*) from service where type_service.type='Ремонт' and service.type_service_id=type_service.id and planes.id=service.plane_id)";
$query="select distinct * from races where races.price>='$price1' and races.price<='$price2' and races.air_time>='$airtime1' and races.air_time<='$airtime2'";
if($to!='') $query .= " and races.to_where='$to'";
$query="select distinct races.* from races, shedule x where x.status='Отменен' and x.race_id=races.id";
if($to!='') $query .= " and races.to_where='$to'";
if($key==number) $query .= " and x.plane_id=pass_planes.id and (pass_planes.n_class1+pass_planes.n_class2-(select count(*) from cash where shedule.id=cash.shedule_id and cash.id not in (select ticket_id from cashback) and shedule.id=x.id))>=$places";
else $query .= " and x.plane_id=pass_planes.id and (pass_planes.n_class1+pass_planes.n_class2-(select count(*) from cash where shedule.id=cash.shedule_id and cash.id not in (select ticket_id from cashback) and shedule.id=x.id))*100/(pass_planes.n_class1+pass_planes.n_class2)>=$places";
$query="select distinct * from races where shedule.status='Задержка' and shedule.race_id=races.id";
if($to!='') $query .= " and races.to_where='$to'";
if($reason!='') $query .= " and shedule.plane_id=service.plane_id and service.reason='$reason'";
if($type==pass) $query="select * from races where shedule.plane_id=pass_planes.id and shedule.race_id=races.id and races.price>=$price1 and races.price<=$price2 and races.air_time>='$airtime1' and races.air_time<='$airtime2' and shedule.time_from>='$time1' and shedule.time_from<='$time2'";
else $query="select * from races where shedule.plane_id=gruz_planes.id and shedule.race_id=races.id and races.price>=$price1 and races.price<=$price2 and races.air_time>='$airtime1' and races.air_time<='$airtime2' and shedule.time_from>='$time1' and shedule.time_from<='$time2'";
if($to!='') $query .= " and races.to_where='$to'";
$query="select distinct * from races where races.id=races.id";
if($to!='') $query .= " and races.to_where='$to'";
if($kateg!='') $query .= " and races.kategory='$kateg'";
if($type==pass) $query .= " and shedule.race_id=races.id and shedule.plane_id=pass_planes.id";
else $query .= " and shedule.race_id=races.id and shedule.plane_id=gruz_planes.id";
$query="select * from cash where cash.age>=$age1 and cash.age<=$age2";
if($sex==male) $query .= " and cash.sex='м'";
elseif($sex==female) $query .= " and cash.sex='ж'";
if($luggage=='on') $query .= " and luggage.ticket_id=cash.id";
if($kategory=='on') $query .= " and races.kategory='международный' and cash.shedule_id=shedule.id and shedule.race_id=races.id";
$query="select count(cashback.*) from cashback,cash where cashback.ticket_id=cash.id and cash.shedule_id=shedule.id and shedule.race_id=races.id and races.price>=$price1 and races.price<=$price2 $list_id and cash.age>=$age1 and cash.age<=$age2";
if($day!='') $query .= " and cashback.date='$day'";
if($to!='') $query .= " and races.to_where='$to'";
if($sex==male) $query .= " and cash.sex='м'";
elseif($sex==female) $query .= " and cash.sex='ж'";
Учитывая первое разбиение базы данных изменятся запросы 11, 12, 13.
Учитывая второе разбиение базы данных изменятся запросы 4, 5, 9, 11, 12, 13.
Время в мсек.
№ Запроса |
Без разбиений |
1 способ |
2 способ |
1 |
17.962 |
17.962 |
17.962 |
2 |
8.060 |
8.060 |
8.060 |
3 |
5.713 |
5.713 |
5.713 |
4 |
8.342 |
8.342 |
9.389 |
5 |
10.946 |
10.946 |
13.231 |
4.764 |
4.764 |
9.809 |
|
6 |
12.069 |
12.069 |
12.069 |
7 |
22.805 |
22.805 |
22.805 |
8 |
4.380 |
4.380 |
4.380 |
9 |
11.209 |
11.209 |
13.589 |
10 |
14.798 |
14.798 |
19.892 |
11 |
7.794 |
8.532 |
8.532 |
13 |
5.548 |
12.482 |
12.482 |
Итого |
134.39 |
142.062 |
157.913 |
Вывод:
1 способ разбиения базы данных информационной системы «аэропорт» считаем оптимальным, так как объем перенесенных данных значителен, а время выполнения запросов меняется не сильно, к тому же благодаря такому разбиению мы можем легче распределить уровни доступа к данным.
При первом разбиении
11 запрос не измениться.
13 запрос
select count(cashback.*) from cashback,cash,public.dblink('dbname=students51 user=pm2109 password=ligzavla','select shedule.id from shedule,races where shedule.race_id=races.id and races.price>=2000 and races.price<=15000') as shedule(id int)
where cashback.ticket_id=cash.id and cash.shedule_id=shedule.id and
cash.age>=20 and cash.age<=50
При втором разбиении
4 запрос
select distinct * from planes, public.dblink('dbname=students51 user=pm2109 password=ligzavla','select plane_id from shedule where shedule.time_from>\'18:00\' and shedule.date_from>=current_date') as shedule(plane_id int)
where planes.num_races>=50 and planes.num_races<=1000 and shedule.plane_id=planes.id and planes.entry_to_airport<='01.01.2005' and planes.entry_to_airport>='01.01.1995'
5 запрос
select distinct * from planes,public.dblink('dbname=students51 user=pm2109 password=ligzavla','select service.plane_id from service, type_service where service.date>=\'01.01.1995\' and service.date<=\'01.01.2005\' and service.type_service_id=type_service.id and type_service.type=\'Ремонт\'') as service (plane_id int)
where planes.num_races>=50 and planes.num_races<=500 and current_date-planes.data_made>=10*365 and planes.id=service.plane_id
select distinct * from planes,public.dblink('dbname=students51 user=pm2109 password=ligzavla','select count(*) from service,type_service where type_service.type=\'Ремонт\' and service.type_service_id=type_service.id ')
as count (c int)
where planes.num_races>=50 and planes.num_races<=500 and current_date-planes.data_made>=10*365 and 5<=count.c
9 запрос
select * from races,public.dblink('dbname=students52 user=pm2109 password=ligzavla','select id from pass_planes
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.