Trop de tables; MySQL peut utiliser seulement 61 tables dans une jointure

Quelle est la meilleure façon d'exporter des données à partir de plusieurs tables dans MySQL. Je suis fondamentalement de travailler avec les détails du produit. Dire qu'un produit a 150 attributs de données. Comment puis-je exporter en une seule ligne, puis de les exporter vers un fichier plat au format CSV ou délimités par des tabulations format.

Avoir d'erreur beaucoup Trop de tables; MySQL peut utiliser seulement 61 tables dans une jointure

/**** Get Resultset *****/
$rs = mysql_query($sql);
/**** End of Get Resultset *****/
$objProfileHistory->addHistory($this->profile_id, "Loaded ". mysql_num_rows($rs)." records");
$this->runQuery($sql);
$this->exportToCSV();
/**
* getAttributeDetails
*/
function getAttributeDetails(){
global $dbObj, $profile;
$base_table = "catalog_product_entity";
$select  = array();
$tables  = array();
$i   = 0;
$profile->showLog("Start fields mapping", "success");
if( is_array($this->attributes_in_db) && sizeof($this->attributes_in_db) > 0 ){
$arr = implode("','", $this->attributes_in_db);
$sql = "select attribute_id, attribute_code, backend_type, frontend_input
from eav_attribute 
where attribute_code in ('".$arr."') 
and entity_type_id = 
(select entity_type_id 
from eav_entity_type 
where entity_type_code = 'catalog_product')";
$rs = $dbObj->customqry($sql);
if( $rs ){
while( $row = mysql_fetch_assoc( $rs ) ){
$backend_type  = $row["backend_type"];
$attribut_code = $row["attribute_code"];
$attribute_id = $row["attribute_id"];
$frontend_input = $row["frontend_input"];
switch( $backend_type ){
case "text":
$where[]  = $base_table."_".$backend_type."".$i.".attribute_id=".$attribute_id;
$and[]  = $base_table.".entity_id=".$base_table."_".$backend_type."".$i.".entity_id";
$select[]  = $base_table."_".$backend_type."".$i.".value as ".$attribut_code;
$tables[]  = $base_table."_".$backend_type." as ".$base_table."_".$backend_type."".$i;
break;
case "decimal":
$where[]  = $base_table."_".$backend_type."".$i.".attribute_id=".$attribute_id;
$and[]  = $base_table.".entity_id=".$base_table."_".$backend_type."".$i.".entity_id";
$select[]  = $base_table."_".$backend_type."".$i.".value as ".$attribut_code;
$tables[]  = $base_table."_".$backend_type." as ".$base_table."_".$backend_type."".$i;
break;
case "static":
$where[]  = $base_table."".$i.".entity_id=".$base_table.".entity_id";
$and[]  = $base_table.".entity_id=".$base_table."".$i.".entity_id";
$select[]  = $base_table."".$i.".".$attribut_code." as ".$attribut_code;
$tables[]  = $base_table." as ".$base_table."".$i;
break;
case "int":
if( $attribut_code == "tax_class_id" && $frontend_input == "select" ){
$where[]  = "tax_class{$i}.class_id=(select ".$base_table."_".$backend_type."".$i.".value from ".$base_table."_".$backend_type." as ".$base_table."_".$backend_type."".$i." where  ".$base_table."_".$backend_type."".$i.".attribute_id=".$attribute_id." and ".$base_table."_".$backend_type."".$i.".entity_id=".$base_table.".entity_id limit 1))";
$and[]  = "";
$select[]  = "tax_class{$i}.class_name as {$attribut_code}";
$tables[]  = "tax_class as tax_class{$i}";
} else if( $frontend_input == "select" ){
$where[]  = "eav_attribute_option_value{$i}.option_id=(select ".$base_table."_".$backend_type."".$i.".value from ".$base_table."_".$backend_type." as ".$base_table."_".$backend_type."".$i." where  ".$base_table."_".$backend_type."".$i.".attribute_id=".$attribute_id." and ".$base_table."_".$backend_type."".$i.".entity_id=".$base_table.".entity_id limit 1))";
$and[]  = "";
$select[] = "eav_attribute_option_value{$i}.value as {$attribut_code}";
$tables[]  = "eav_attribute_option_value as eav_attribute_option_value{$i}";
} else {
$where[]  = $base_table."_".$backend_type."".$i.".attribute_id=".$attribute_id;
$and[]  = $base_table.".entity_id=".$base_table."_".$backend_type."".$i.".entity_id";
$select[]  = $base_table."_".$backend_type."".$i.".value as ".$attribut_code;
$tables[]  = $base_table."_".$backend_type." as ".$base_table."_".$backend_type."".$i;
}
break;
case "varchar":
$where[]  = $base_table."_".$backend_type."".$i.".attribute_id=".$attribute_id;
$and[]  = $base_table.".entity_id=".$base_table."_".$backend_type."".$i.".entity_id";
$select[]  = $base_table."_".$backend_type."".$i.".value as ".$attribut_code;
$tables[]  = $base_table."_".$backend_type." as ".$base_table."_".$backend_type."".$i;
break;
case "datetime":
$where[]  = $base_table."_".$backend_type."".$i.".attribute_id=".$attribute_id;
$and[]  = $base_table.".entity_id=".$base_table."_".$backend_type."".$i.".entity_id";
$select[]  = $base_table."_".$backend_type."".$i.".value as ".$attribut_code;
$tables[]  = $base_table."_".$backend_type." as ".$base_table."_".$backend_type."".$i;
break;
}//switch
$i++;
}//while
$sql = "select ".implode(",", $select)." from ".$base_table;
for($i=0; $i < sizeof($select); $i++){
$sql .= " left join ". $tables[$i] . " on (".$where[$i];//." and ".$and[$i].")";
if( strlen($and[$i]) > 0 ){
$sql .= " and ".$and[$i].")";
}
}//for
$sql .= " group by {$base_table}.entity_id ";
}//if
//echo $sql; exit;
return $sql;
}
//echo $sql;
//echo "<pre>";print_r($tables);print_r($select);print_r($where);print_r($and);
}//end function
/**
* runQuery
*/
function runQuery( $sql ){
global $dbObj, $profile;
if( $sql != "" ){
$rs = $dbObj->customqry( $sql );
$profile->showLog("Loaded ". mysql_num_rows($rs) ." records", "success");
if( $rs ){
$i = 0;
while( $row = mysql_fetch_assoc( $rs ) ){
$cnt = sizeof($this->attributes_in_db);
for($j=0; $j < $cnt; $j++){
$db_key  = $this->attributes_in_db[$j];
$file_key = $this->attributes_in_file[$j];
$this->export_data[$i][$db_key] = $row[$db_key];
}
$i++;
}//while
}
}//if
}//end function
/**
* exportToCSV
*/
function exportToCSV(){
global $smarty, $objProfileHistory, $profile;
//$newFileName = $smarty->root_dir."/export/".$this->filename; //file name that you want to create
$cnt = sizeof($this->var_array);
for($i=0; $i < $cnt; $i++){
extract($this->var_array[$i]);
}//for
if( $delimiter = "\t" ){
$delimiter = "\t";//$delimiter;
}
if( strlen($filename) < 1 ){
$filename = time().".csv";
}
//    echo "<pre>";
//    print_r($this->action_array);
//    print_r($this->var_array);
//    print_r($this->map_array);
//    exit;
# add amazon headers
if( $this->action_array[0]['type'] == 'header' ){
//     $template_type  = $this->var_array[0]['template_type'];
//     $version   = $this->var_array[0]['version'];
//     $status_message = $this->var_array[0]['status_message'];
$sStr = "TemplateType=".$template_type."{$delimiter}{$delimiter}Version=".$version."{$delimiter}{$delimiter}{$status_message}";
$sStr .= "� ��\n"; //to seprate every record
}
$export_path = $path;
$x_path = $profile->createDir( $export_path );
$newFileName = $x_path ."/". $filename;
$fpWrite = fopen($newFileName, "w"); // open file as writable
# create header
$cnt_header = sizeof($this->attributes_in_file);
for( $i=0; $i < $cnt_header; $i++){
$sStr .= $deli . $this->attributes_in_file[$i];
$deli = $delimiter;
}//for
$sStr .= "� ��\n"; //to seprate every record
# attach data
$cnt_row = sizeof($this->export_data);
for( $i=0; $i < $cnt_row; $i++ ){
$sStr .= $saperator;
$newdeli = "";
for($j=0; $j < $cnt_header; $j++){
$key  = $this->attributes_in_db[$j];
$sku = $this->export_data[$i]["sku"];
QUELLE EST LA MEILLEURE FAÇON D'EXPORTER DES DONNÉES À PARTIR DE PLUSIEURS TABLES DANS MYSQL. M ESSENTIELLEMENT TRAVAILLER AVEC LES DÉTAILS DU PRODUIT. DIRE qu'UN PRODUIT A 150 attributs de données comment puis-je exporter en une seule ligne, puis de les exporter vers un fichier plat au format csv ou délimités par des tabulations format.
Le temps de repenser à cette requête. De joindre plus de l'ordre de 7 tables est une performance killer pour toute base de données. Avez-vous jamais exécuter cette requête n'importe où?

OriginalL'auteur user204245 | 2009-11-06