MySQL 实战 45 讲 Part1

MySQL 实战 45 讲 | 林晓斌 01 | 基础架构:一条 SQL 查询语句是如何执行的? 连接器:跟客户端建立连接、获取权限、维持和管理连接。 SHOW PROCESSLIST; 137462239 db 10.135.4.7:41261 db Query 0 starting show processlist -- 一个空闲连接 137462293 db 10.130.128.1:47174 db Sleep 24 -- 客户端如果太长时间没动静,连接器就会自动将它断开 select @@wait_timeout; show variables like 'wait_timeout'; -- 28800 8h 通过执行 mysql_reset_connection 来重新初始化连接资源,这是个接口函数,不是一个 SQL 语句。 查询缓存:不建议使用。在一个表上有更新的时候,跟这个表有关的查询缓存都会失效。 select @@query_cache_type; -- OFF sysvar_query_cache_type | mysql 分析器:词法分析、语法分析。进行分词和验证语法规则。解析器和预处理器。 解析器处理语法和解析查询,生成一课对应的解析树。 预处理器进一步检查解析树的合法。比如: 数据表和数据列是否存在,别名是否有歧义等。如果通过则生成新的解析树,再提交给优化器。 优化器:决定使用哪个索引,决定各个表的连接顺序。 执行器:有没有执行查询的权限,操作引擎,返回结果。执行器调用的次数(rows_examined)与引擎总共扫描行数可能是不等的,后文有例子。 读写、存取数据在 engine 引擎层,连接、鉴权、计算在 server 服务层。 ...

August 14, 2022 · 6 min · 1198 words · Me

Shell Code Snippet

Package Management Find Packages with pkgs.org pkgs.org is a Linux package search website that helps you find software packages for various Linux distributions. # Check installed package versions (Red Hat/CentOS) rpm -qa | grep docker Process Management Run Commands in Background # Run in background (will stop when terminal closes) cmd & # Run in background (continues after terminal closes) nohup cmd & Control Background Jobs Ctrl + Z - Pause the current foreground job and move it to background jobs - List all background jobs (jobs -l shows PIDs) fg - Bring the most recent background job to foreground fg %N - Bring job number N to foreground bg - Resume the most recent job in the background bg %N - Resume job number N in the background Using fg Command # Restore the most recent background job fg # Restore a specific job by number fg 1 # Restore using % syntax fg %2 # Restore by process name fg %vim # List all background jobs jobs DNS Operations Lookup CNAME Records CNAME (Canonical Name) records map one domain name to another, commonly used for subdomains or third-party hosted services. ...

July 28, 2022 · 4 min · 746 words · Me

Front-end Code Snippet

库推荐 nrm Pana/nrm nrm can help you easy and fast switch between different npm registries, now include: npm, cnpm, taobao, nj(nodejitsu). npm install -g nrm nrm ls nrm use tencent Website W3Techs - World Wide Web Technology Surveys nodejs release schedule References – EOF –

July 26, 2022 · 1 min · 45 words · Me

【JavaScript 教程 | 网道】笔记

JavaScript 教程 | 网道(WangDoc.com) JavaScript 语言的历史 ECMAScript 只用来标准化 JavaScript 这种语言的基本语法结构,与部署环境相关的标准都由其他标准规定,比如 DOM 的标准就是由 W3C 组织(World Wide Web Consortium)制定的。 2011 年 6 月,ECMAScript 5.1 版发布,并且成为 ISO 国际标准(ISO/IEC 16262:2011)。到了 2012 年底,所有主要浏览器都支持 ECMAScript 5.1 版的全部功能。 2015 年 6 月,ECMAScript 6 正式发布,并且更名为“ECMAScript 2015”。这是因为 TC39 委员会计划,以后每年发布一个 ECMAScript 的版本,下一个版本在 2016 年发布,称为“ECMAScript 2016”,2017 年发布“ECMAScript 2017”,以此类推。 JavaScript 的基本语法 如果只是声明变量而没有赋值,则该变量的值是 undefined。undefined 是一个特殊的值,表示“无定义”。 var a; a; // undefined JavaScript 是一种动态类型语言,也就是说,变量的类型没有限制,变量可以随时更改类型。 var a = 1; a = "hello"; 如果使用 var 重新声明一个已经存在的变量,是无效的。 var x = 1; var x; x; // 1 JavaScript 引擎的工作方式是,先解析代码,获取所有被声明的变量,然后再一行一行地运行。这造成的结果,就是所有的变量的声明语句,都会被提升到代码的头部,这就叫做变量提升(hoisting)。 ...

June 9, 2022 · 6 min · 1235 words · Me

GROUP_CONCAT 截断

今日在生产环境发生了:因为 GROUP_CONCAT 聚合的数据列发生截断导致异常,原来 GROUP_CONCAT 是有大小限制的。 SELECT @@GROUP_CONCAT_MAX_LEN; -- 1024 bytes References group_concat_max_len | mysql – EOF –

January 10, 2022 · 1 min · 17 words · Me

回顾 2021

直到对的人来 · 追星族乐队 我想跟他说:那家餐厅太美了,我一定要和你去一次。但是那个菜其实很一般的,那个老板娘戴的耳环特别漂亮。 – EOF –

December 31, 2021 · 1 min · 7 words · Me

PHP 安装 gRPC

ENV cat /etc/redhat-release CentOS Linux release 7.2 (Final) uname -a Linux xxx-xxx 3.10.107-1-tlinux2_kvm_guest-0052 #1 SMP Wed Jan 15 18:42:19 CST 2020 x86_64 x86_64 x86_64 GNU/Linux PECL pecl install grpc 如果遇到: Connection to `ssl://pecl.php.net:443′ failed: 参考: PHP Swoft 框架环境配置 | ZYF.IM Build 通用手动安装 PECL 扩展 For this to work, you’ll need to have root access to your server, and you’ll most probably need developer tools installed as well. https://pecl.php.net/ # 创建临时目录 mkdir /tmp/download/ && cd /tmp/download/ # 下载 wget http://pecl.php.net/get/[extension].tgz # 解压 tar -xvf [extension].tgz cd [extension] # 配置 phpize # 查看参数 ./configure --help # 设置参考 以实际情况为准 ./configure --enable-[extension] # 编译 make && make test # 安装 make install # 查看 ini 路径 php --ini # 开启 vi [php-ini].ini extension=[extension].so gcc is currently not installed yum install gcc ...already installed and latest version... gcc ...gcc is currently not installed. yum reinstall gcc # 重新安装后解决 GrpcLb::TokenAndClientStatsAttribute::ToString() const 原因:gcc 版本过低。 ...

October 13, 2021 · 1 min · 175 words · Me

分组聚合 OVER PARTITION BY

在 HIVE 中 最近在使用 HIVE,需要统计 当年累计和 这样的指标,请教同事后发现了 OVER(PARTITION BY) 开窗函数。 分析函数用于计算基于组的某种聚合值,它和聚合函数的不同之处是:对于每个组返回多行,而聚合函数对于每个组只返回一行。 开窗函数指定了分析函数工作的数据窗口大小,这个数据窗口大小可能会随着行的变化而变化。 测试语句: CREATE TABLE default.test_over_partition ( `fdate` Date, `year` Int, `month` Int, `category1` String, `category2` String, `income` Double ); INSERT INTO hdp_fin_dash_ods.test_over_partition (`fdate`,`year`,`month`,`category1`,`category2`,`income`) VALUES ('2020-01-01',2020,1,'3C','电脑','1010'), ('2020-01-01',2020,1,'3C','手机','1011'), ('2020-02-01',2020,2,'3C','电脑','1012'), ('2020-02-01',2020,2,'3C','手机','1013'), ('2020-03-01',2020,3,'3C','电脑','1014'), ('2020-03-01',2020,3,'3C','手机','1015'), ('2021-04-01',2021,4,'3C','电脑','1016'), ('2021-04-01',2021,4,'3C','手机','1017'), ('2021-05-01',2021,5,'3C','电脑','1018'), ('2021-05-01',2021,5,'3C','手机','1019'); -- 查询每年每 category2 日累计 income SELECT `fdate`,`year`,`month`,`category1`,`category2`,`income` ,SUM(income) OVER (PARTITION BY `year`,`category1`,`category2` ORDER BY fdate) AS ttl_year_income FROM hdp_fin_dash_ods.test_over_partition; 在 MySQL 中 Before MySQL 8.0 you can’t use window functions like ROW_NUMBER. ...

September 14, 2021 · 1 min · 97 words · Me

PHP __invoke 使用

why they are magic? Because they are magically called by PHP when specific actions happen. The __invoke() method is called when a script tries to call an object as a function. <?php class CallableClass { public function __invoke($x) { var_dump($x); } } $obj = new CallableClass; $obj(5); var_dump(is_callable($obj)); int(5) bool(true) 使用明显的操作方法初始化 例如,当我们有一个提供者时,就会发生这种情况。 aws-sdk-php/src/Endpoint/PatternEndpointProvider.php public function __invoke(array $args = []) { $service = isset($args['service']) ? $args['service'] : ''; $region = isset($args['region']) ? $args['region'] : ''; $keys = ["{$region}/{$service}", "{$region}/*", "*/{$service}", "*/*"]; foreach ($keys as $key) { if (isset($this->patterns[$key])) { return $this->expand( $this->patterns[$key], isset($args['scheme']) ? $args['scheme'] : 'https', $service, $region ); } } return null; } 它使用 invoke 使用一些参数提供端点。我们如何使用这个类? ...

July 20, 2021 · 2 min · 305 words · Me

PHP strict_types 严格模式

严格模式的声明 必须 放在文件的顶部。 严格模式不仅作用于函数参数的类型声明,也作用于函数的返回值类型。 声明 PHP 文件作为严格模式的一个好事是,实际上只适用于当前文件。这确保了这个文件是严格类型,但是他没有影响到整个项目中的其他文件。这允许你一步一步的迁移非严格模式的代码。 使用提示类型没有 strict_types 可能导致微妙的错误。 严格类型之前,int $x 意味着 $x must have a value coercible to an int。 a float (example: 13.1459 -> 13) a bool (example: true -> 1) a null (example: null -> 0) a string with leading digits (example: “15 Trees” -> 15) 设置严格模式后,you tell the engine that int $x means $x must only be an int proper, no type coercion allowed。 谁给更关心 strict_type 这行?is more for the reader than for the writer. Why? Bacause it will explicitly tell the reader: ...

July 19, 2021 · 2 min · 349 words · Me