首页 > 数据库 >Mysql Non cluster combined fields select where order by field different time cost

Mysql Non cluster combined fields select where order by field different time cost

时间:2024-09-12 11:48:11浏览次数:1  
标签:index Non LOGS firstname fields field cost lastname FLUSH

use mydb;
drop table if exists t1;
create table t1
(id int auto_increment primary key,
firstname varchar(100) not null default '',
lastname varchar(100) not null default '',
index fn_ln_index(firstname, lastname)
);

 

FLUSH BINARY LOGS;
FLUSH ENGINE LOGS;
FLUSH ERROR LOGS;
FLUSH GENERAL LOGS;
FLUSH RELAY LOGS;
FLUSH SLOW LOGS;
use mydb;
EXPLAIN FORMAT=JSON INTO @myselect 
select id,firstname,lastname from t1 where firstname='ln_10000000';
select @myselect;


{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "1.02"
    },
    "table": {
      "table_name": "t1",
      "access_type": "ref",
      "possible_keys": [
        "fn_ln_index"
      ],
      "key": "fn_ln_index",
      "used_key_parts": [
        "firstname"
      ],
      "key_length": "402",
      "ref": [
        "const"
      ],
      "rows_examined_per_scan": 1,
      "rows_produced_per_join": 1,
      "filtered": "100.00",
      "using_index": true,
      "cost_info": {
        "read_cost": "0.93",
        "eval_cost": "0.10",
        "prefix_cost": "1.03",
        "data_read_per_join": "816"
      },
      "used_columns": [
        "id",
        "firstname",
        "lastname"
      ]
    }
  }
}

 

 

 

 

 

FLUSH BINARY LOGS;
FLUSH ENGINE LOGS;
FLUSH ERROR LOGS;
FLUSH GENERAL LOGS;
FLUSH RELAY LOGS;
FLUSH SLOW LOGS;
use mydb;
EXPLAIN FORMAT=JSON INTO @myselect 
select id,firstname,lastname from t1 where firstname='fn_10000000';
select @myselect;


{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "1.06"
    },
    "table": {
      "table_name": "t1",
      "access_type": "ref",
      "possible_keys": [
        "fn_ln_index"
      ],
      "key": "fn_ln_index",
      "used_key_parts": [
        "firstname"
      ],
      "key_length": "402",
      "ref": [
        "const"
      ],
      "rows_examined_per_scan": 1,
      "rows_produced_per_join": 1,
      "filtered": "100.00",
      "using_index": true,
      "cost_info": {
        "read_cost": "0.96",
        "eval_cost": "0.10",
        "prefix_cost": "1.06",
        "data_read_per_join": "816"
      },
      "used_columns": [
        "id",
        "firstname",
        "lastname"
      ]
    }
  }
}



FLUSH BINARY LOGS;
FLUSH ENGINE LOGS;
FLUSH ERROR LOGS;
FLUSH GENERAL LOGS;
FLUSH RELAY LOGS;
FLUSH SLOW LOGS;
use mydb;
EXPLAIN FORMAT=JSON INTO @myselect 
select id,firstname,lastname from t1 where firstname='fn_10000000' and lastname='ln_10000000';
select @myselect;


{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "1.07"
    },
    "table": {
      "table_name": "t1",
      "access_type": "ref",
      "possible_keys": [
        "fn_ln_index"
      ],
      "key": "fn_ln_index",
      "used_key_parts": [
        "firstname",
        "lastname"
      ],
      "key_length": "804",
      "ref": [
        "const",
        "const"
      ],
      "rows_examined_per_scan": 1,
      "rows_produced_per_join": 1,
      "filtered": "100.00",
      "using_index": true,
      "cost_info": {
        "read_cost": "0.97",
        "eval_cost": "0.10",
        "prefix_cost": "1.07",
        "data_read_per_join": "816"
      },
      "used_columns": [
        "id",
        "firstname",
        "lastname"
      ]
    }
  }
}




FLUSH BINARY LOGS;
FLUSH ENGINE LOGS;
FLUSH ERROR LOGS;
FLUSH GENERAL LOGS;
FLUSH RELAY LOGS;
FLUSH SLOW LOGS;
use mydb;
EXPLAIN FORMAT=JSON INTO @myselect 
select id,firstname,lastname from t1 where lastname='ln_10000000' and firstname='fn_10000000';
select @myselect;


{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "1.07"
    },
    "table": {
      "table_name": "t1",
      "access_type": "ref",
      "possible_keys": [
        "fn_ln_index"
      ],
      "key": "fn_ln_index",
      "used_key_parts": [
        "firstname",
        "lastname"
      ],
      "key_length": "804",
      "ref": [
        "const",
        "const"
      ],
      "rows_examined_per_scan": 1,
      "rows_produced_per_join": 1,
      "filtered": "100.00",
      "using_index": true,
      "cost_info": {
        "read_cost": "0.97",
        "eval_cost": "0.10",
        "prefix_cost": "1.07",
        "data_read_per_join": "816"
      },
      "used_columns": [
        "id",
        "firstname",
        "lastname"
      ]
    }
  }
}

 

FLUSH BINARY LOGS;
FLUSH ENGINE LOGS;
FLUSH ERROR LOGS;
FLUSH GENERAL LOGS;
FLUSH RELAY LOGS;
FLUSH SLOW LOGS;
use mydb;
EXPLAIN FORMAT=JSON INTO @myselect 
select id,firstname,lastname from t1 where lastname='ln_10000000';
select @myselect;

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "3150663.64"
    },
    "table": {
      "table_name": "t1",
      "access_type": "index",
      "possible_keys": [
        "fn_ln_index"
      ],
      "key": "fn_ln_index",
      "used_key_parts": [
        "firstname",
        "lastname"
      ],
      "key_length": "804",
      "rows_examined_per_scan": 30667649,
      "rows_produced_per_join": 3066764,
      "filtered": "10.00",
      "using_index": true,
      "cost_info": {
        "read_cost": "2843987.16",
        "eval_cost": "306676.47",
        "prefix_cost": "3150663.64",
        "data_read_per_join": "2G"
      },
      "used_columns": [
        "id",
        "firstname",
        "lastname"
      ],
      "attached_condition": "(`mydb`.`t1`.`lastname` = 'ln_10000000')"
    }
  }
}

 

标签:index,Non,LOGS,firstname,fields,field,cost,lastname,FLUSH
From: https://www.cnblogs.com/Fred1987/p/18409888

相关文章

  • [1059] Operations of None in pandas
    Inpandas,handlingNonevalues(whicharerepresentedasNaNinDataFrames)isacommontask.Herearesomewaystodealwiththem:FilteringRowsFilterRowswithNoneValues:importpandasaspd#SampleDataFramedf=pd.DataFrame({'A......
  • CSS中元素将不再响应鼠标事件(如点击、悬停等)。pointer-events: none;
    按钮点击无效pointer-events:none; 是一种CSS样式规则,用于指定元素在用户与之交互时的行为。当应用了 pointer-events:none; 样式时,元素将不再响应鼠标事件(如点击、悬停等),即使用户点击该元素上的内容,也不会触发任何与该元素相关的事件。主要作用:禁用用户交互:当将 p......
  • 导入数据至数据集时报错Meta endpoint! Unexpected status code: 502, with response
    我的dify服务器是在内网环境,首先它需要通过代理去调用LLM,但打开代理后调用difyweaviate服务会报错:Metaendpoint!Unexpectedstatuscode:502,withresponsebody:None.所以,需要做的是:既要在调用LLM的时候走代理,又要调用difyweaviate服务的时候不走代理。配置如下:di......
  • ElasticSearch 备考 -- Runtime Field
    一、题目在集群上有索引task,请编写查询并满足要求:定义一个名为field_num的运行时字段,实现以下聚合(a字段的值等于field_x字段减去field_y字段),field_num聚合区间如下:聚合值小于0的文档聚合0到100之间的文档聚合大于100的文档二、思考1)运行时字段第一反应runtimefil......
  • 记录elasticsearch-analysis-dynamic-synonym从8.7.0升级到8.15.0所遇到的问题
    记录elasticsearch-analysis-dynamic-synonym从8.7.0升级到8.15.0所遇到的问题一、问题伊始今天打算用elasticsearch最新版本来学点东西,发现安装es插件就遇到了许多问题,于是便通过此篇博客来记录问题的整个过程。去年我学习用的elasticsearch版本为8.7.0,当时GitHub有一个大佬直......
  • 【Material-UI】Text Field中的 Performance 优化详解
    文章目录一、TextField组件概述1.组件介绍2.性能挑战二、全局样式注入行为的优化1.问题的根源2.禁用全局样式注入3.自定义全局样式三、实际场景中的性能优化应用1.大规模表单中的优化2.动态表单生成中的优化3.提升用户体验四、最佳实践与注意事项1.谨慎使......
  • CF1980F1 & F2 Field Division
    前言纪念一下独立做出来的\(2400\)的题Easyversion思路先说\(Easy\)版本的我们走路的方式只有可能是这种样子:(出处:luoguuserFiraCode)不想手绘图了即对列排序后,所形成的一个行编号上升的序列所以\(Easy\)就很简单了,对于每一列的最大值,如果大于当前前缀最大值,则......
  • ptrade排坑日记——交易策略报错: ‘NoneType‘ object is not subscriptable 。
    前言今天要和大家分享的一个问题是交易策略报错,希望大家在使用ptrade过程中遇见这个问题能够快速解决!一、问题描述交易策略报错: File"/home/fly/sim_backtest/result/412974e0-a014-11ee-8735-d4f5ef8c353c/user_strategy.py",line354,inocall_BS  px_change_ra......
  • Nond.Js基础(2)——请求响应与HTTP协议
    目录一、请求响应与HTTP协议1、创建web服务器 2、请求与响应1、req2、res3、根据不同url地址处理请求:3、HTTP协议请求报文:get类型接口:post类型接口: 响应报文:一、请求响应与HTTP协议1、创建web服务器 //引入模块consthttp=require('http');//http.creat......
  • 网站提示431 Request Header Fields Too Large:请求头字段太大怎么办
    当遇到“431RequestHeaderFieldsTooLarge”错误时,这意味着客户端发送的请求头中的一个或多个字段超过了服务器允许的最大长度。这种情况通常发生在请求头中的某个字段(如Cookie或Authorization)过长时。解决方案检查请求头确认请求头中的字段是否过长。特别注意Cook......