-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1356 lines (938 loc) · 55 KB
/
index.html
File metadata and controls
1356 lines (938 loc) · 55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
<link rel="mask-icon" href="/images/logo.svg" color="#222">
<link rel="stylesheet" href="/css/main.css">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
<script id="hexo-configurations">
var NexT = window.NexT || {};
var CONFIG = {"hostname":"viggoc.github.io","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
</script>
<meta property="og:type" content="website">
<meta property="og:title" content="VC' Blog">
<meta property="og:url" content="https://viggoc.github.io/index.html">
<meta property="og:site_name" content="VC' Blog">
<meta property="og:locale" content="en_US">
<meta property="article:author" content="VC">
<meta name="twitter:card" content="summary">
<link rel="canonical" href="https://viggoc.github.io/">
<script id="page-configurations">
// https://hexo.io/docs/variables.html
CONFIG.page = {
sidebar: "",
isHome : true,
isPost : false,
lang : 'en'
};
</script>
<title>VC' Blog</title>
<noscript>
<style>
.use-motion .brand,
.use-motion .menu-item,
.sidebar-inner,
.use-motion .post-block,
.use-motion .pagination,
.use-motion .comments,
.use-motion .post-header,
.use-motion .post-body,
.use-motion .collection-header { opacity: initial; }
.use-motion .site-title,
.use-motion .site-subtitle {
opacity: initial;
top: initial;
}
.use-motion .logo-line-before i { left: initial; }
.use-motion .logo-line-after i { right: initial; }
</style>
</noscript><!-- hexo-inject:begin --><!-- hexo-inject:end -->
</head>
<body itemscope itemtype="http://schema.org/WebPage">
<!-- hexo-inject:begin --><!-- hexo-inject:end --><div class="container use-motion">
<div class="headband"></div>
<header class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-container">
<div class="site-nav-toggle">
<div class="toggle" aria-label="Toggle navigation bar">
<span class="toggle-line toggle-line-first"></span>
<span class="toggle-line toggle-line-middle"></span>
<span class="toggle-line toggle-line-last"></span>
</div>
</div>
<div class="site-meta">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<h1 class="site-title">VC' Blog</h1>
<span class="logo-line-after"><i></i></span>
</a>
</div>
<div class="site-nav-right">
<div class="toggle popup-trigger">
<i class="fa fa-search fa-fw fa-lg"></i>
</div>
</div>
</div>
<nav class="site-nav">
<ul id="menu" class="menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section"><i class="fa fa-fw fa-home"></i>Home</a>
</li>
<li class="menu-item menu-item-tags">
<a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>Tags</a>
</li>
<li class="menu-item menu-item-categories">
<a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>Categories</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>Archives</a>
</li>
<li class="menu-item menu-item-search">
<a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>Search
</a>
</li>
</ul>
</nav>
<div class="search-pop-overlay">
<div class="popup search-popup">
<div class="search-header">
<span class="search-icon">
<i class="fa fa-search"></i>
</span>
<div class="search-input-container">
<input autocomplete="off" autocapitalize="off"
placeholder="Searching..." spellcheck="false"
type="search" class="search-input">
</div>
<span class="popup-btn-close">
<i class="fa fa-times-circle"></i>
</span>
</div>
<div id="search-result">
<div id="no-result">
<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
</div>
</div>
</div>
</div>
</div>
</header>
<div class="back-to-top">
<i class="fa fa-arrow-up"></i>
<span>0%</span>
</div>
<main class="main">
<div class="main-inner">
<div class="content-wrap">
<div class="content index posts-expand">
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
<link itemprop="mainEntityOfPage" href="https://viggoc.github.io/2020/04/covid-19-risk/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="VC">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="VC' Blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/04/covid-19-risk/" class="post-title-link" itemprop="url">疫情风险等级爬虫小记</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-04-12 13:51:55" itemprop="dateCreated datePublished" datetime="2020-04-12T13:51:55+08:00">2020-04-12</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-check-o"></i>
</span>
<span class="post-meta-item-text">Edited on</span>
<time title="Modified: 2020-04-16 15:39:05" itemprop="dateModified" datetime="2020-04-16T15:39:05+08:00">2020-04-16</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">In</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/Python/" itemprop="url" rel="index"><span itemprop="name">Python</span></a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>近日看到国务院印发的《全国不同风险地区企事业单位复工复产疫情防控措施指南》中提到了低风险,中风险和高风险地区,搜索发现只能通过“国务院客户端微信小程序”以区/县为单位进行查询,想了解一下全国各地的形式需要挨个查询,没有一个可以纵览全局的地图,心血来潮想要自己画一个。</p>
<h2 id="数据源"><a class="markdownIt-Anchor" href="#数据源"></a> 数据源</h2>
<p>网上常见的查询入口都是微信小程序,但是微信小程序相对封闭,咱也不属于数据获取相对不方便,想找个普通的网站服务。经过一番搜索发现国家政务服务平台也提供了一个<a href="http://gjzwfw.www.gov.cn/fwmh/healthCode/front/indexAreaRisk.do" target="_blank" rel="noopener">区/县疫情风险等级查询入口</a>,开干。</p>
<!--noindex-->
<div class="post-button">
<a class="btn" href="/2020/04/covid-19-risk/#more" rel="contents">
Read more »
</a>
</div>
<!--/noindex-->
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
<link itemprop="mainEntityOfPage" href="https://viggoc.github.io/2020/04/high-perf-mysql11/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="VC">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="VC' Blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/04/high-perf-mysql11/" class="post-title-link" itemprop="url">可扩展的 MySQL</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-04-05 12:51:55" itemprop="dateCreated datePublished" datetime="2020-04-05T12:51:55+08:00">2020-04-05</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-check-o"></i>
</span>
<span class="post-meta-item-text">Edited on</span>
<time title="Modified: 2020-04-11 19:31:33" itemprop="dateModified" datetime="2020-04-11T19:31:33+08:00">2020-04-11</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">In</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/Database/" itemprop="url" rel="index"><span itemprop="name">Database</span></a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>在 MySQL 的规模越来越大时,如何保证快速、高效且经济。</p>
<h2 id="什么是可扩展性"><a class="markdownIt-Anchor" href="#什么是可扩展性"></a> 什么是可扩展性</h2>
<p>容易混淆的用词:可扩展性,高可用性,性能。</p>
<p>可扩展性就是能过够通过增加资源提升容量(工作效率)的能力。表明了当需要增加资源以执行更过工作时系统能够划算地提供等同提升(equal bang for the buck)的能力。另一种说法是,可扩展性是当增加资源以处理负载和增加容量时系统能够获得的投入产出比。</p>
<p>大部分系统都没办法做到线性扩展,越高的扩展系数导致越大的线性偏差,最终达到临界点。—— 详见通用可扩展定律(Universal Scalability Law,USL)</p>
<!--noindex-->
<div class="post-button">
<a class="btn" href="/2020/04/high-perf-mysql11/#more" rel="contents">
Read more »
</a>
</div>
<!--/noindex-->
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
<link itemprop="mainEntityOfPage" href="https://viggoc.github.io/2020/03/high-perf-mysql10/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="VC">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="VC' Blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/03/high-perf-mysql10/" class="post-title-link" itemprop="url">Mysql 复制</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-03-13 19:51:55" itemprop="dateCreated datePublished" datetime="2020-03-13T19:51:55+08:00">2020-03-13</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-check-o"></i>
</span>
<span class="post-meta-item-text">Edited on</span>
<time title="Modified: 2020-04-09 00:56:58" itemprop="dateModified" datetime="2020-04-09T00:56:58+08:00">2020-04-09</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">In</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/Database/" itemprop="url" rel="index"><span itemprop="name">Database</span></a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h2 id="概述"><a class="markdownIt-Anchor" href="#概述"></a> 概述</h2>
<p>复制功能不仅有利于构建高性能的应用,同时也是高可用、可扩展性、容灾恢复、备份以及数据仓库等工作的基础。</p>
<p>MySQL 支持两种复制方式:</p>
<ul>
<li>基于行的复制</li>
<li>基于语句的复制(也称为逻辑复制)</li>
</ul>
<p>两种方式都是通过在主库上记录二进制日志,在备库中重放日志实现异步的数据复制,因此存在延迟。</p>
<p>MySQL 的复制大部分后向兼容,新版本的服务器可以作为老版本服务器的备库,但反之不行,因为它可能无法解析新版中的新特性或语法。对于小版本号升级通常是兼容的。</p>
<!--noindex-->
<div class="post-button">
<a class="btn" href="/2020/03/high-perf-mysql10/#more" rel="contents">
Read more »
</a>
</div>
<!--/noindex-->
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
<link itemprop="mainEntityOfPage" href="https://viggoc.github.io/2020/02/high-perf-mysql06/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="VC">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="VC' Blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/02/high-perf-mysql06/" class="post-title-link" itemprop="url">查询性能优化</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-02-13 13:21:55" itemprop="dateCreated datePublished" datetime="2020-02-13T13:21:55+08:00">2020-02-13</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-check-o"></i>
</span>
<span class="post-meta-item-text">Edited on</span>
<time title="Modified: 2020-10-23 11:44:04" itemprop="dateModified" datetime="2020-10-23T11:44:04+08:00">2020-10-23</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">In</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/Database/" itemprop="url" rel="index"><span itemprop="name">Database</span></a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>表结构优化、索引优化、查询优化缺一不可,需要齐头并进。</p>
<h2 id="嵌套循环算法"><a class="markdownIt-Anchor" href="#嵌套循环算法"></a> 嵌套循环算法</h2>
<p>MySQL 的联表算法是基于嵌套循环算法(nested-loop algorithm)而衍生出来的一系列算法,根据不同条件而选用不同的算法</p>
<ul>
<li>在使用索引关联的情况下,有 Index Nested-Loop join 和 Batched Key Access join 两种算法;</li>
<li>在未使用索引关联的情况下,有 Simple Nested-Loop join 和 Block Nested-Loop join 两种算法;</li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">// Simple Nested-Loop</span><br><span class="line"><span class="keyword">for</span> each row <span class="keyword">in</span> t1 matching range {</span><br><span class="line"> <span class="keyword">for</span> each row <span class="keyword">in</span> t2 matching reference key {</span><br><span class="line"> <span class="keyword">for</span> each row <span class="keyword">in</span> t3 {</span><br><span class="line"> <span class="keyword">if</span> row satisfies join conditions, send to client</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">// Block Nested-Loop</span><br><span class="line"><span class="keyword">for</span> each row <span class="keyword">in</span> t1 matching range {</span><br><span class="line"> <span class="keyword">for</span> each row <span class="keyword">in</span> t2 matching reference key {</span><br><span class="line"> store used columns <span class="keyword">from</span> t1, t2 <span class="keyword">in</span> join buffer</span><br><span class="line"> <span class="keyword">if</span> buffer <span class="keyword">is</span> full {</span><br><span class="line"> <span class="keyword">for</span> each row <span class="keyword">in</span> t3 {</span><br><span class="line"> <span class="keyword">for</span> each t1, t2 combination <span class="keyword">in</span> join buffer {</span><br><span class="line"> <span class="keyword">if</span> row satisfies join conditions, send to client</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> empty join buffer</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> buffer <span class="keyword">is</span> <span class="keyword">not</span> empty {</span><br><span class="line"> <span class="keyword">for</span> each row <span class="keyword">in</span> t3 {</span><br><span class="line"> <span class="keyword">for</span> each t1, t2 combination <span class="keyword">in</span> join buffer {</span><br><span class="line"> <span class="keyword">if</span> row satisfies join conditions, send to client</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p><code>Simple Nested-Loop</code> 最为简单粗暴,毫无性能可言,事实上不会使用这种算法。</p>
<p><code>Block Nested-Loop</code> 缓存块嵌套循环连接,简称 BNL,是对 SNL 的一种优化。一次性缓存多条驱动表的数据到 Join Buffer,然后拿 Join Buffer 里的数据批量与内层循环读取的数据进行匹配。将内部循环中读取的每一行与缓冲区中的所有记录进行比较,这样就可以减少内层循环的读表次数。原来内层循环的读表次数是外层循环的行数 n,如今读表次数为 n/buffer_size。</p>
<p><code>Index Nested-Loop</code> 索引嵌套循环,简称 INL,是基于被驱动表的索引进行连接的算法;驱动表的记录逐条与被驱动表的索引进行匹配,避免和被驱动表的每条记录进行比较。</p>
<p><code>Batched Key Access</code> 是对INL的进一步优化,详见<a href="https://dev.mysql.com/doc/refman/5.7/en/bnl-bka-optimization.html" target="_blank" rel="noopener">文档</a>。</p>
<h2 id="查询速度为什么会变慢"><a class="markdownIt-Anchor" href="#查询速度为什么会变慢"></a> 查询速度为什么会变慢</h2>
<p>查询需要在不同的地方花费时间,包括网络,CPU 计算,生成统计信息和执行计划,锁等待等操作,尤其是底层存储引擎检索数据,这些检索需要内存操作、CPU 操作和内存不足时的 IO 操作。</p>
<h2 id="慢查询基础优化数据访问"><a class="markdownIt-Anchor" href="#慢查询基础优化数据访问"></a> 慢查询基础:优化数据访问</h2>
<p>分析步骤</p>
<ol>
<li>确认应用程序是否检索大量不必要的的数据,太多行或太多列。</li>
<li>确认 MySQL 服务器层是否在分析大量不必要的数据行。</li>
</ol>
<h3 id="是否向数据库请求了多余的数据"><a class="markdownIt-Anchor" href="#是否向数据库请求了多余的数据"></a> 是否向数据库请求了多余的数据</h3>
<ul>
<li>
<p>查询不需要的记录<br />
使用 SELECT 查询所有结果,获取前面的 N 行后关闭,实际上 MySQL 已经查询出全部结果。需要多少查多少,用 LIMIT 进行限制。</p>
</li>
<li>
<p>取出全部列<br />
不要使用 <code>SELECT * FROM a INNER JOIN b INNER JOIN C;</code>这样的语句。很多时候取出全部列是不必要的。并且,取出全部列会让优化器无法完成索引覆盖这类优化,还会为服务器带来额外的 IO、内存和 CPU 的消耗。<br />
有时候出于开发效率,应用程序可以通过缓存进行复用等角度也可以查询这些多余的数据,需要进行权衡。</p>
</li>
<li>
<p>重复查询相同的数据<br />
利用缓存,减少重复查询。</p>
</li>
</ul>
<!--noindex-->
<div class="post-button">
<a class="btn" href="/2020/02/high-perf-mysql06/#more" rel="contents">
Read more »
</a>
</div>
<!--/noindex-->
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
<link itemprop="mainEntityOfPage" href="https://viggoc.github.io/2020/02/high-perf-mysql05/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="VC">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="VC' Blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/02/high-perf-mysql05/" class="post-title-link" itemprop="url">创建高性能的索引</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-02-12 16:32:38" itemprop="dateCreated datePublished" datetime="2020-02-12T16:32:38+08:00">2020-02-12</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-check-o"></i>
</span>
<span class="post-meta-item-text">Edited on</span>
<time title="Modified: 2020-08-26 21:30:45" itemprop="dateModified" datetime="2020-08-26T21:30:45+08:00">2020-08-26</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">In</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/Database/" itemprop="url" rel="index"><span itemprop="name">Database</span></a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h2 id="索引基础"><a class="markdownIt-Anchor" href="#索引基础"></a> 索引基础</h2>
<p>索引可以包含一个或多个列的值,MySQL 只能高效地使用索引的最左前缀,如果索引包含多个列,那么列的顺序也十分重要。</p>
<p><strong>B 树索引</strong></p>
<p>B 树中所有的值按顺序存储,每个叶节点到根的距离相同。</p>
<p>索引对多个值进行排序的依据是<code>CREATE TABLE</code>语句中定义索引时列的顺序。</p>
<p>B 树适用于全键值、键值范围或键前缀查找:</p>
<ul>
<li>全值匹配:和索引中的所有列进行匹配</li>
<li>匹配最左前缀:只使用索引的第一列</li>
<li>匹配列前缀:只匹配某一列的开头部分</li>
<li>匹配范围值:匹配值处于某个区间</li>
<li>精确匹配某一列并范围匹配另一列</li>
<li>只访问索引的查询</li>
</ul>
<p>索引树中的节点是有序的,因此还可以用于查询中的<code>ORDER BY</code>操作。如果<code>ORDER BY</code>子句满足前面列出的集中查询类型,则索引也可以满足对应的排序需求。</p>
<p>B 树索引的限制:</p>
<ul>
<li>如果不是按照索引的最左列开始查找,则无法使用索引。如为<code>last_name, first_name, birthday</code>创建索引,索引无法用于查询名字为 Bill 的人,也无法用于查找某个特定的生日。类似的,无法查找姓氏以某个字结尾的人。</li>
<li>不能跳过索引中的列。前述的索引无法用于查找特定姓氏并且在某个特定生日的人,如果不指定 first_name,只能使用索引的第一列。</li>
<li>如果查询中有某个列的范围查询,则其右边所有的列无法使用索引优化查询。</li>
</ul>
<!--noindex-->
<div class="post-button">
<a class="btn" href="/2020/02/high-perf-mysql05/#more" rel="contents">
Read more »
</a>
</div>
<!--/noindex-->
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
<link itemprop="mainEntityOfPage" href="https://viggoc.github.io/2020/02/high-perf-mysql04/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="VC">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="VC' Blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/02/high-perf-mysql04/" class="post-title-link" itemprop="url">Schema 与数据类型优化</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-02-07 19:32:38" itemprop="dateCreated datePublished" datetime="2020-02-07T19:32:38+08:00">2020-02-07</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-check-o"></i>
</span>
<span class="post-meta-item-text">Edited on</span>
<time title="Modified: 2020-08-26 21:30:51" itemprop="dateModified" datetime="2020-08-26T21:30:51+08:00">2020-08-26</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">In</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/Database/" itemprop="url" rel="index"><span itemprop="name">Database</span></a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h2 id="选择优化的数据类型"><a class="markdownIt-Anchor" href="#选择优化的数据类型"></a> 选择优化的数据类型</h2>
<p>选择数据类型的原则</p>
<ul>
<li>更小的通常更好。应该尽量使用可以正确存储数据的最小数据类型,更小的数据类型占用更少的磁盘、内存和 CPU 缓存,处理时需要的 CPU 周期也更少。<strong>但也要确保没有低估需要存储的值的范围</strong>。<em>(个人觉得字符串的长度限制有时候真的很难把握)</em></li>
<li>简单就好。简单数据类型的操作通常需要更少的 CPU 周期,整型的代价比字符串低,内建时间类型比字符串低,用整型存储 IP 比字符串低。</li>
<li>尽量避免使用<code>NULL</code>。查询可为 NULL 的列对于 MySQL 来说更难优化,这些列使得索引、索引统计和值比较都更复杂。</li>
</ul>
<!--noindex-->
<div class="post-button">
<a class="btn" href="/2020/02/high-perf-mysql04/#more" rel="contents">
Read more »
</a>
</div>
<!--/noindex-->
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
<link itemprop="mainEntityOfPage" href="https://viggoc.github.io/2020/02/high-perf-mysql01/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="VC">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="VC' Blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/02/high-perf-mysql01/" class="post-title-link" itemprop="url">MySQL 架构和历史</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-02-07 16:32:38" itemprop="dateCreated datePublished" datetime="2020-02-07T16:32:38+08:00">2020-02-07</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-check-o"></i>
</span>
<span class="post-meta-item-text">Edited on</span>
<time title="Modified: 2020-09-05 20:19:36" itemprop="dateModified" datetime="2020-09-05T20:19:36+08:00">2020-09-05</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">In</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/Database/" itemprop="url" rel="index"><span itemprop="name">Database</span></a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h2 id="逻辑架构"><a class="markdownIt-Anchor" href="#逻辑架构"></a> 逻辑架构</h2>
<p>三层架构:</p>
<ul>
<li>连接与线程处理</li>
</ul>
<p>每个连接拥有一个线程,线程的创建和销毁消耗资源,可以通过维护线程池的方式,提高性能。<br />
注意区分<code>线程池</code>和<code>连接池</code>,连接池一般在客户端设置,而线程池是在 DB 服务器上配置。连接池可以减少连接的创建和释放,提高请求的平均响应时间,控制一个应用的 DB 连接数,但无法控制整个应用集群的连接数规模。<code>线程池</code>和<code>连接池</code>需要结合使用。</p>
<ul>
<li>MySQL 服务层:SQL 解析、分析、优化、缓存</li>
</ul>
<p>MySQL 的优化器不关心使用的是什么存储引擎,但存储引擎对于优化查询有影响。优化器会请求存储引擎提供容量或某个具体操作的开销信息,以及表数据的统计信息。<br />
Oracle 中有库基于规则优化 (RBO) 和基于代价优化 (CBO) 两种方式,但<code>oracle 10g</code>之后已经弃用 RBO。相比 MySQL 的优化器,Oracle 的优化更加丰富和完善,可以对照着学习。</p>
<ul>
<li>存储引擎</li>
</ul>
<!--noindex-->
<div class="post-button">
<a class="btn" href="/2020/02/high-perf-mysql01/#more" rel="contents">
Read more »
</a>
</div>
<!--/noindex-->
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
<link itemprop="mainEntityOfPage" href="https://viggoc.github.io/2020/02/fluent-python/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="VC">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="VC' Blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2020/02/fluent-python/" class="post-title-link" itemprop="url">Fluent Python 笔记</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-02-05 09:51:55" itemprop="dateCreated datePublished" datetime="2020-02-05T09:51:55+08:00">2020-02-05</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-check-o"></i>
</span>
<span class="post-meta-item-text">Edited on</span>
<time title="Modified: 2020-04-12 16:13:37" itemprop="dateModified" datetime="2020-04-12T16:13:37+08:00">2020-04-12</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">In</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/Python/" itemprop="url" rel="index"><span itemprop="name">Python</span></a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h2 id="术语解释"><a class="markdownIt-Anchor" href="#术语解释"></a> 术语解释</h2>
<p>doctest: 一种单元测试工具</p>
<p>genxp: generator expression</p>
<p>listcomp: list comprehension</p>
<!--noindex-->
<div class="post-button">
<a class="btn" href="/2020/02/fluent-python/#more" rel="contents">
Read more »
</a>
</div>
<!--/noindex-->
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
<link itemprop="mainEntityOfPage" href="https://viggoc.github.io/2019/12/ML_algorithm/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="VC">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="VC' Blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2019/12/ML_algorithm/" class="post-title-link" itemprop="url">常见机器学习算法的优缺点</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2019-12-20 20:03:55" itemprop="dateCreated datePublished" datetime="2019-12-20T20:03:55+08:00">2019-12-20</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-check-o"></i>
</span>
<span class="post-meta-item-text">Edited on</span>
<time title="Modified: 2020-03-29 23:07:54" itemprop="dateModified" datetime="2020-03-29T23:07:54+08:00">2020-03-29</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">In</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/AI/" itemprop="url" rel="index"><span itemprop="name">AI</span></a>
</span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>想要寻找一个合适的算法不容易,实际应用中,我们一般采用启发式实验。</p>
<p>没有免费的午餐定理 (NFL):核心在于,假设了所有问题出现的机会相同,或所有问题同等重要。当需求是解决一切问题时,“哪个算法更好”就毫无意义。HG2G 中“深思”面对“宇宙、生命以及一切的中继答案是什么?”这样一个问题,用最复杂的算法算出一个 42 和随便说一个 42 是一样的。</p>
<h2 id="偏差与方差"><a class="markdownIt-Anchor" href="#偏差与方差"></a> 偏差与方差</h2>