Skip to content
Extraits de code Groupes Projets
Valider f68455a8 rédigé par esj's avatar esj
Parcourir les fichiers

reduire le nombre de jointures

parent e39f9d96
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -57,6 +57,7 @@ class Boucle { ...@@ -57,6 +57,7 @@ class Boucle {
var $select = array(); var $select = array();
var $from = array(); var $from = array();
var $where = array(); var $where = array();
var $join = array();
var $having = 0; var $having = 0;
var $limit; var $limit;
var $group = array(); var $group = array();
......
...@@ -225,13 +225,11 @@ function calculer_boucle($id_boucle, &$boucles) { ...@@ -225,13 +225,11 @@ function calculer_boucle($id_boucle, &$boucles) {
(!$boucle->select ? 1 : (!$boucle->select ? 1 :
join("\",\n\t\t\"", $boucle->select)) . join("\",\n\t\t\"", $boucle->select)) .
'"), # SELECT '"), # SELECT
' . calculer_from($boucle->from) . ' . calculer_from($boucle) .
', # FROM ', # FROM
array(' . ' . calculer_where($boucle) .
(!$boucle->where ? '' : ( '"' . join('", ', # WHERE
"', $boucle->where) . '"')) . ' . (!$boucle->group ? "''" :
"), # WHERE
" . (!$boucle->group ? "''" :
('"' . join(", ", $boucle->group)) . '"') . ('"' . join(", ", $boucle->group)) . '"') .
", # GROUP ", # GROUP
array(" . array(" .
...@@ -275,13 +273,22 @@ function calculer_boucle($id_boucle, &$boucles) { ...@@ -275,13 +273,22 @@ function calculer_boucle($id_boucle, &$boucles) {
"\n return \$t0;"; "\n return \$t0;";
} }
function calculer_from($t) function calculer_from(&$boucle)
{ {
$res = ""; $res = "";
foreach($t as $k => $v) $res .= "\", \"$v AS $k"; foreach($boucle->from as $k => $v) $res .= "\", \"$v AS $k";
return 'array(' . substr($res,3) . '")'; return 'array(' . substr($res,3) . '")';
} }
function calculer_where(&$boucle)
{
$w = array_merge($boucle->where, $boucle->join);
return 'array(' .
(!$w ? '' : ( '"' . join('",
"', $w) . '"')) .
")";
}
// //
// fonction traitant les criteres {1,n} (analyses dans inc-criteres) // fonction traitant les criteres {1,n} (analyses dans inc-criteres)
// //
......
...@@ -544,9 +544,11 @@ function calculer_jointure(&$boucle, $depart, $arrivee) ...@@ -544,9 +544,11 @@ function calculer_jointure(&$boucle, $depart, $arrivee)
$res = calculer_chaine_jointures($boucle, $depart, $arrivee); $res = calculer_chaine_jointures($boucle, $depart, $arrivee);
if (!$res) return ""; if (!$res) return "";
$n = ""; $n = "";
$i = count($res);
foreach($res as $r) { foreach($res as $r) {
list($d, $a, $j) = $r; list($d, $a, $j) = $r;
$n = calculer_critere_externe($boucle, ($n ? "L$n" : $d), $a, $j); $i--;
$n = calculer_critere_externe($boucle, ($n ? "L$n" : $d), $a, $j, $i);
} }
return $n; return $n;
} }
...@@ -571,7 +573,6 @@ function calculer_chaine_jointures(&$boucle, $depart, $arrivee, $vu=array()) ...@@ -571,7 +573,6 @@ function calculer_chaine_jointures(&$boucle, $depart, $arrivee, $vu=array())
$new[] = $v; $new[] = $v;
$r = calculer_chaine_jointures($boucle, array($table, $join), $arrivee, $new); $r = calculer_chaine_jointures($boucle, array($table, $join), $arrivee, $new);
if ($r) if ($r)
{ {
array_unshift($r, array($dnom, $table, $k)); array_unshift($r, array($dnom, $table, $k));
return $r; return $r;
...@@ -630,14 +631,19 @@ function trouver_champ_exterieur($cle, $joints, &$boucle) ...@@ -630,14 +631,19 @@ function trouver_champ_exterieur($cle, $joints, &$boucle)
} }
// traitement des relations externes par DES jointures. // traitement des relations externes par DES jointures.
// mais ne pas dupliquer les jointures intermediaires
function calculer_critere_externe(&$boucle, $id_table, $lien, $join) { function calculer_critere_externe(&$boucle, $id_table, $lien, $join, $suite) {
static $num; static $num;
$id_field = $id_table . '.' . $join; $id_field = $id_table . '.' . $join;
if ($suite)
foreach ($boucle->join as $v) {
if (ereg("^$id_field=L([0-9]+)\.$join$",$v, $r)) return $r[1];
}
$num++; $num++;
$boucle->lien = true; $boucle->lien = true;
$boucle->from["L$num"] = $lien; $boucle->from["L$num"] = $lien;
$boucle->where[] = "$id_field=L$num." . $join; $boucle->join[] = "$id_field=L$num." . $join;
if (!in_array($id_field, $boucle->group)) if (!in_array($id_field, $boucle->group))
$boucle->group[] = $id_field; $boucle->group[] = $id_field;
// postgres exige que le champ pour GROUP soit dans le SELECT // postgres exige que le champ pour GROUP soit dans le SELECT
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter