【问题标题】:Mysql select speedmysql选择速度
【发布时间】:2011-11-14 03:34:37
【问题描述】:

我对 mysql 查询的速度有疑问。 我有 2 个带有国家和城市的选择框,首先选择第二个更改城市,它由 ajax 提供:

$(document).ready(function()
{

$(".country").change(function()
{
var id=$(this).val(); 
var dataString = 'id='+ id;
function doAJAX(url) {

$.ajax
({
type: "POST",
url: url,

data: dataString,
cache: false,
success: function(html)
{
$(".city").html(html); 
}

});
}




doAJAX('search_ajax.php');
});
});

例如西班牙或俄罗斯什么时候有这么多城市,显示它们花费了太多时间,表城市:fips 2 varchar,城市 varchar 100, 我的选择:

SELECT city from cities where fips='some value' //for example EN or any ..

我有关于列 fips 的索引。

有人可以帮助 mi 加快速度吗?还是除了ajax之外更好的解决方案来实时更改选择?谢谢

【问题讨论】:

  • 您是否真的对其进行了分析以证明查询本身很慢,而不是系统的其他部分?
  • 用profile了,你的意思是查询系统的时间?我找到了 percona-toolkit,但它没有在 Windows 上运行,并且处于显示状态,我不知道如何阅读它:(

标签: mysql ajax


【解决方案1】:

尝试在列 fips 上创建索引。

【讨论】:

  • 我已经在 fips 列上输入了索引
【解决方案2】:

我不知道它是否可以标记为解决方案,但是我通过在mysql请求时添加加载gif来解决它,也许它会对某人有所帮助,函数更改为:

function doAJAX(url) {
    $(".city").hide(); // hide the select
    $("#Div1").show(); // show loading gif
    $("#Div1").html('<img src="images/loading2.gif"> Loading...'); 
    $.ajax({   
        type: "POST",
        url: url,    
        data: dataString,
        cache: false,
        success: function(html){
            $(".city").html(html);
            $(".city").show(); // on succes show select
            $("#Div1").hide(); // and hide the loading
        }
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-17
    • 2014-03-10
    • 2011-12-22
    • 2012-02-07
    • 1970-01-01
    • 2014-10-29
    • 2020-11-06
    • 1970-01-01
    相关资源
    最近更新 更多