Oracle DB-Abfrage mit SQL zu langsam (time_out)

trinity

Grünschnabel
Hallo an Alle,

hoffentlich könnt Ihr mir helfen.
Mit der unten stehenden Class versuche ich eine Ansicht zu erstellen, die aus den Spalten Anzahl, Hdw_key, Hersteller, Hdw_n besteht.
Um diese jeweiligen Felder aus der Oracle-DB zu selektieren, habe ich die Daten in ein Array gepackt um sie wiederum mit foreach auszugeben.
Nun habe ich das Problem das der Report zwar auf unserer Testmaschine einwandfrei läuft, jedoch sobald der Report auf der Live-Maschine genutzt wird, habe ich einen Time out:
"
Read Timeout
The system returned:

[No Error]
A Timeout occurred while waiting to read data from the network. The network or server may be down or congested. Please retry your request.
"

Serverseitig ist alles in Ordnung.
Da ich mich noch nicht so lang mit php beschäftige, weiß ich leider nicht so genau wie ich das ganze optimieren soll, so daß der Report auch live läuft. Das ganze hängt wohl mit der Menge an Datensätzen zusammen, die natürlich auf der Live-Maschine enorm ist.

Und hier nun die dazugehörige Class.

<?php
set_time_limit(0);
class cTopData {
var $conn;


function cTopData () {
include ("/opt/...."); # DB Login
$this->conn = OCIPLogon("$db_login", "$db_password", "$db_tnsname");
}

function rollback () {
OCIRollback ($this->conn);
}

function commit () {
OCICommit ($this->conn);
}

function get_hardware(hdw_key) {
list($obest_type,$ref,$wako,$shid,$tag,$monat,$jahr,
$akid,$html_status,$choice, $report_choice) = $report_values;


$dbcmd = "SELECT SUM(oi.anzahl), oi.hdw_key,
m.m_n,
h.hdw_n
FROM obest_t o, sa_tr sa, oitems oi, hdw h, man_m m
WHERE o.obest_key = oi.obest_key
AND o.obest_key = sa.obest_key
AND oi.hdw_key = h.hdw_key
AND h.m_key = m.m_key";

switch ($choice) {

case 1: $dbcmd = $dbcmd." AND:)obest_type IS NULL OR o.obest_type = :eek:best_type)";break;
case 2: $dbcmd = $dbcmd." AND:)ref IS NULL OR o.ref = :ref)";break;
case 3: $dbcmd = $dbcmd." AND(o.ref like :akid OR :akid IS NULL)";break;
}
$dbcmd=$dbcmd. "AND:)html_status IS NULL OR sa.trst = :html_status)
AND:)tag IS NULL OR to_char(o.dat_insert, 'dd') = :tag)
AND:)monat IS NULL OR to_char(o.dat_insert, 'mm') = :monat)
AND:)wako IS NULL OR f_obest_type(o.obest_key) = :wako)
AND:)jahr IS NULL OR to_char(o.dat_insert, 'yyyy') = :jahr)
AND:)shid IS NULL OR o.shid = :shid)
AND oi.hdw_key != 0
AND sa.trst = 0
GROUP BY oi.hdw_key,
m.m_n,
h.hdw_n order by sum(oi.anzahl) DESC";


$stmt=OCIparse($this->conn, $dbcmd);


switch ($choice) {

case 1:OCIBindByName($stmt, ":eek:best_type", $obest_type, strlen($obest_type));break;
case 2:OCIBindByName($stmt, ":ref", $ref, strlen($ref));break;
case 3:OCIBindByName($stmt, ":akid", $akid, strlen($akid));break;
}

OCIBindByName($stmt, ":html_status", $html_status, strlen($html_status));
OCIBindByName($stmt, ":tag", $tag, strlen($tag));
OCIBindByName($stmt, ":monat", $monat, strlen($monat));
OCIBindByName($stmt, ":jahr", $jahr, strlen($jahr));
OCIBindByName($stmt, ":wako", $wako, strlen($wako));
OCIBindByName($stmt, ":shid", $shid, strlen($shid));
OCIexecute($stmt, OCI_DEFAULT);
$h = 0;
while (OCIfetchinto($stmt, $feedback)) {
list($m_n, $hdw_key, $hdw_n, $Anzahl) = $feedback;

$output_hdw[$h] = array (
"Hersteller"=>$m_n,
"Hdw_key"=>$hdw_key,
"Hdw_n"=>$hdw_n,
"Anzahl"=>$Anzahl,
);
$h++;
}
return $output_hdw;
}


function show_output_top ($output_hdw,$report_values) {

$show_data = $show_data . "
<tr bgcolor=99cc00>
<td class=myfont4>Anzahl&nbsp;</td>
<td class=myfont4>Hdw_key&nbsp;</td>
<td class=myfont4>Hersteller&nbsp;</td>
<td class=myfont4>Hdw_n&nbsp;</td>
</tr>";

foreach ($output_hdw as $cc=>$details){
if ($bunt==true) $coloro="#dddddd";
else $coloro="#eeeeee";
$bunt = !$bunt;
$show_data = $show_data. "<tr bgcolor=$coloro>";
foreach ($details as $hh=>$elem) {
$show_data = $show_data."\n<td class=myfont2>$elem</td>";

}
}
return $show_data;
}
}

?>

Ich danke Euch jetzt schon für Eure Hilfe !!!

Bye
 
Zurück