English 中文(简体)
长期问题
原标题:Long running query issues

I m 试图用文字I.nt做一些问题,在这些问题上,该网址似乎正在填上我的sql <代码>/tmp。 页: 1

我检查了<条码>查询记录,并提出了许多问题。

SELECT
    COUNT(*) AS `total`
FROM
    (
        SELECT
                *
        FROM
            `Advertising_Business_and_Retail`
        WHERE
            MATCH (`wm`, `locn`, `gns`) AGAINST( outdoor apparel company )
    UNION
        SELECT
                *
        FROM
            `Chemical` WHERE MATCH (`wm`, `locn`, `gns`) AGAINST( outdoor apparel company )
    UNION
        SELECT
                *
        FROM `Clothing` WHERE MATCH (`wm`, `locn`, `gns`) AGAINST( outdoor apparel company )
    )
AS t;

除我外,我相信45的工会总数(每类表格1次),这些表格是巨大的,但<代码>。 广告_Business_and_Retail 表格本身有<代码>450k。

我以人工方式处理这个问题,大约需要2分钟半。

我猜想的是,为什么 /mp正在迅速填补?

对于我能做些什么来解决这个问题,有什么推论?

最佳回答

如果你知道你正在选择的行文中不存在重复,请将<条码>改为<条码>。

此外,还可将<代码>UINON ALL改为简单添加:

select (
  (select count(1) from `Advertising_Business_and_Retail` WHERE MATCH (`wm`, `locn`, `gns`) AGAINST( outdoor apparel company ))
+ (select count(1) from `Chemical` WHERE MATCH (`wm`, `locn`, `gns`) AGAINST( outdoor apparel company ))
+ (select count(1) from `Clothing` WHERE MATCH (`wm`, `locn`, `gns`) AGAINST( outdoor apparel company ))
) as total
问题回答

这是否越快?

SELECT
    SUM(`count`) AS `total`
FROM
    (
        SELECT
               COUNT(*) AS `count`
        FROM
            `Advertising_Business_and_Retail`
        WHERE
            MATCH (`wm`, `locn`, `gns`) AGAINST( outdoor apparel company )
    UNION
        SELECT
               COUNT(*) AS `count`
        FROM
            `Chemical` WHERE MATCH (`wm`, `locn`, `gns`) AGAINST( outdoor apparel company )
    UNION
        SELECT
                COUNT(*) AS `count`
        FROM `Clothing` WHERE MATCH (`wm`, `locn`, `gns`) AGAINST( outdoor apparel company )
    )
AS t;




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签