bug 649665 rows count and UNION

This commit is contained in:
Marc Delisle
2003-07-08 15:35:39 +00:00
parent da2701f6a6
commit dc4c462297
3 changed files with 34 additions and 10 deletions

View File

@@ -7,7 +7,8 @@ $Source$
2003-07-08 Marc Delisle <lem9@users.sourceforge.net>
* libraries/sqlparser.lib.php3, sql.php3: bug 762213,
incorrect row count for MySQL 4.1 subqueries
incorrect row count for MySQL 4.1 subqueries;
bug 649665, incorrect row count for UNIONs
2003-07-08 Michal Cihar <nijel@users.sourceforge.net>
* config.inc.php3, tbl_properties_operations.php3,

View File

@@ -713,6 +713,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
* ['queryflags']['need_confirm'] = 1; if the query needs confirmation
* ['queryflags']['select_from'] = 1; if this is a real SELECT...FROM
* ['queryflags']['distinct'] = 1; for a DISTINCT
* ['queryflags']['union'] = 1; for a UNION
*
* lem9: query clauses
* -------------
@@ -1230,6 +1231,10 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
$subresult['queryflags']['distinct'] = 1;
}
if ($upper_data == 'UNION') {
$subresult['queryflags']['union'] = 1;
}
// if this is a real SELECT...FROM
if ($upper_data == 'FROM' && isset($subresult['queryflags']['select_from']) && $subresult['queryflags']['select_from'] == 1) {
$in_from = TRUE;
@@ -1475,12 +1480,16 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
* Formats SQL queries to html
*
* @param array The SQL queries
* @param string mode
* @param integer starting token
* @param integer number of tokens to format, -1 = all
*
* @return string The formatted SQL queries
*
* @access public
*/
function PMA_SQP_formatHtml($arr, $mode='color', $start_token=0)
function PMA_SQP_formatHtml($arr, $mode='color', $start_token=0,
$number_of_tokens=-1)
{
// first check for the SQL parser having hit an error
if (PMA_SQP_isError()) {
@@ -1560,7 +1569,11 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
);
$keywords_priv_list_cnt = 2;
$arraysize = $arr['len'];
if ($number_of_tokens == -1) {
$arraysize = $arr['len'];
} else {
$arraysize = $number_of_tokens;
}
$typearr = array();
if ($arraysize >= 0) {
$typearr[0] = '';

View File

@@ -355,7 +355,9 @@ else {
// because SQL_CALC_FOUND_ROWS
// is not quick on large InnoDB tables
if (!$is_group && !isset($analyzed_sql[0]['table_ref'][1]['table_name'])
if (!$is_group
&& !isset($analyzed_sql[0]['queryflags']['union'])
&& !isset($analyzed_sql[0]['table_ref'][1]['table_name'])
&& (empty($analyzed_sql[0]['where_clause'])
|| $analyzed_sql[0]['where_clause'] == '1 ')) {
@@ -373,9 +375,6 @@ else {
$count_query = 'SELECT COUNT(' . $count_what . ') AS count';
}
else {
$count_query = 'SELECT SQL_CALC_FOUND_ROWS ';
}
// add the remaining of select expression if there is
// a GROUP BY or HAVING clause
@@ -386,13 +385,22 @@ else {
$count_query .= ' ,' . $analyzed_sql[0]['select_expr_clause'];
}
// add select expression after the SQL_CALC_FOUND_ROWS
if (PMA_MYSQL_INT_VERSION >= 40000) {
// add select expression after the SQL_CALC_FOUND_ROWS
// if (eregi('DISTINCT(.*)', $sql_query)) {
// $count_query .= 'DISTINCT ' . $analyzed_sql[0]['select_expr_clause'];
// } else {
//$count_query .= $analyzed_sql[0]['select_expr_clause'];
// for UNION, just adding SQL_CALC_FOUND_ROWS
// after the first SELECT works.
// take the left part, could be:
// SELECT
// (SELECT
$count_query = PMA_SQP_formatHtml($parsed_sql, 'query_only', 0, $analyzed_sql[0]['position_of_first_select'] + 1);
$count_query .= ' SQL_CALC_FOUND_ROWS ';
// add everything that was after the first SELECT
$count_query .= PMA_SQP_formatHtml($parsed_sql, 'query_only', $analyzed_sql[0]['position_of_first_select']+1);
// }
@@ -414,13 +422,15 @@ else {
// if using SQL_CALC_FOUND_ROWS, add a LIMIT to avoid
// long delays. Returned count will be complete anyway.
// (but a LIMIT would disrupt results in an UNION)
if (PMA_MYSQL_INT_VERSION >= 40000) {
if (PMA_MYSQL_INT_VERSION >= 40000
&& !isset($analyzed_sql[0]['queryflags']['union'])) {
$count_query .= ' LIMIT 1';
}
// run the count query
//echo "trace cq=" . $count_query . "<br/>";
//DEBUG echo "trace cq=" . $count_query . "<br/>";
if (PMA_MYSQL_INT_VERSION < 40000) {
if ($cnt_all_result = PMA_mysql_query($count_query)) {