ठीक है मैंने एक छोटी सी लिपि बनाई है जो आप चाहते हैं कि वास्तव में क्या कर सकता है, और शायद अन्य क्या चाहते हैं ... तो यहां यह PHP के लिए ... पहले आपको कॉलम की सूची बनाना है तालिका के बाद, आप अपने कॉलम के आधार पर प्रत्येक कॉलम के लिए "केस कब" कथन बनाते हैं और उसे concat_ws कथन में डालते हैं और फिर आप इसे sha1 के साथ रखते हैं ... मैंने इस विधि को बहुत बड़ी टेबल पर उपयोग किया है (600000+ रिकॉर्ड) और सभी रिकॉर्ड चुनते समय गति काफी अच्छी है। भी मुझे लगता है कि यह एक concat_ws में आवश्यक डेटा concat और php या जो भी आप उपयोग कर रहे हैं में यह विस्फोट के लिए तेजी से होता है, लेकिन यह सिर्फ एक कूबड़ है ...
<?
$query= mysql_query("SHOW COLUMNS FROM $table", $linklive);
while ($col = mysql_fetch_assoc($query)) {
$columns[] = mysql_real_escape_string($col['Field']);
if ($col['Key'] == 'PRI') {
$key = mysql_real_escape_string($col['Field']);
}
$columnsinfo[$col['Field']] = $col;
}
$dates = array("date","datetime","time");
$int = array("int","decimal");
$implcols = array();
foreach($columns as $col){
if(in_array($columnsinfo[$col]['Type'], $dates)){
$implcols[] = "(CASE WHEN (UNIX_TIMESTAMP(`$col`)=0 || `$col` IS NULL) THEN '[$col EMPTY]' ELSE `$col` END)";
}else{
list($type, $rest) = explode("(",$columnsinfo[$col]['Type']);
if(in_array($columnsinfo[$col]['Type'], $dates)){
$implcols[] = "(CASE WHEN (`$col`=0 || `$col` IS NULL) THEN '[$col EMPTY]' ELSE `$col` END)";
}else{
$implcols[] = "(CASE WHEN (`$col`='' || `$col` IS NULL) THEN '[$col EMPTY]' ELSE `$col` END)";
}
}
}
$keyslive = array();
//echo "SELECT $key SHA1(CONCAT_WS('',".implode(",", $columns).")) as compare FROM $table"; exit;
$q = "SELECT $key as `key`, SHA1(CONCAT_WS('',".implode(", ",$implcols).")) as compare FROM $table";
?>
स्रोत
2012-10-29 14:12:55
कि पागल लग रहा है –