Commit cfcc5b01 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

database: Revision 9

Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
parent 08933345
......@@ -161,14 +161,19 @@ begin
raise log 'Done';
/* ---------------------------------------------------------------------- */
/* Get minimum date from which the load must take effect */
select min(contact_date) into min_date from tmp_inventory;
-- TODO: Exclude duplicate entries to avoid an error when inserting the data
-- TODO: This query needs a revision and a test to see if it's really faster to use the hash or to compare the fields themselves
/* Insert new data into fact_inventory using the temporary tables */
raise log 'Inserting new machines inventories and contacts into '
'"fact_inventory"...';
insert into fact_inventory (load_date, contact_date, machine_id, os_id,
kernel_id, processor_id, memory_size, hd_id, hd_used, hd2_id, hd2_used,
extra_hds, hash)
select distinct on (contact_date, machine_id, hash) load_date_id,
--select distinct on (contact_date, machine_id, hash) load_date_id,
select load_date_id,
contact_date, machine_id, os_id, kernel_id, processor_id,
memory_size, hd_id, hd_used, hd2_id, hd2_used, extra_hds,
md5(os_id::text || kernel_id::text || processor_id::text ||
......@@ -176,15 +181,15 @@ begin
coalesce(hd2_id::text, '') || coalesce(hd2_used::text, '') ||
coalesce(extra_hds::text, '0')) as hash
from tmp_inventory s
join tmp_join j using (contact_date, machine, inep);
join tmp_join j using (contact_date, machine, inep)
except select load_date_id, contact_date, machine_id, os_id, kernel_id,
processor_id, memory_size, hd_id, hd_used, hd2_id, hd2_used,
extra_hds, hash from fact_inventory where contact_date >= min_date;
get diagnostics tmp = ROW_COUNT;
count_total := count_total + tmp;
raise log 'Done - % rows inserted', tmp;
/* Get minimum date from which the load must take effect in fact_alert */
select min(contact_date) into min_date from tmp_inventory;
-- TODO: This query needs a revision and a test to see if it's really faster to use the hash or to compare the fields themselves
-- TODO: It needs a revision
/* Insert machine modifications data into fact_alert */
raise log 'Inserting alert data from "fact_inventory" to "fact_alert"...';
insert into fact_alert (load_date, old_inventory, inventory, memory_alert,
......@@ -211,6 +216,9 @@ begin
/* ---------------------------------------------------------------------- */
/* Update network usage fact tables */
/* Get minimum date from which the load must take effect */
select min(collect_time::date) into min_date from tmp_net_usage;
-- TODO: Try creating a temporary index and exclude repeated entries
raise log 'Inserting new network usage data into "fact_net_usage"...';
insert into fact_net_usage (load_date, machine_id, collect_time, down_kbits,
......@@ -218,7 +226,10 @@ begin
select load_date_id, m.id, collect_time, down_kbits, down_packages,
up_kbits, up_packages from tmp_net_usage n, dim_machine m,
dim_school s where n.machine = m.machine and n.inep = s.inep and
m.school_id = s.id;
m.school_id = s.id
except select load_date_id, machine_id, collect_time, down_kbits,
down_packages, up_kbits, up_packages from fact_net_usage where
collect_time::date >= min_date;
get diagnostics tmp = ROW_COUNT;
count_total := count_total + tmp;
raise log 'Done - % rows inserted', tmp;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment