-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
rule.json
1455 lines (1408 loc) · 44.9 KB
/
rule.json
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
{
"_id" : ObjectId("5b61644153cc7e049902d11b"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : 10.0,
"output_parms" : [
{
"parm_desc" : "CHECKSUM",
"parm_name" : "CHECKSUM"
},
{
"parm_desc" : "执行次数",
"parm_name" : "ts_cnt"
},
{
"parm_desc" : "平均执行时间",
"parm_name" : "query_time_avg"
},
{
"parm_desc" : "平均返回记录数",
"parm_name" : "rows_sent_avg"
},
{
"parm_desc" : "扫描命中率",
"parm_name" : "index_ratio"
}
],
"rule_complexity" : "simple",
"rule_cmd" : "db.planitem.find({\"schemas\":\"@schema_name@\",\"item_type\" : \"materialized_from_subquery\"}).forEach(function(x){db.sqlinfo.find({checksum:x.checksum}).forEach(function(y){db.@tmp@.save({\"checksum\" :y.checksum,\"ts_cnt\" :y.ts_cnt,\"query_time_avg\" :y.query_time_avg,\"rows_sent_avg\" :y.rows_sent_avg,\"index_ratio\" :y.index_ratio})})})",
"rule_desc" : "materialized_from_subquery",
"rule_name" : "MATERIALIZED_FROM_SUBQUERY",
"rule_status" : "ON",
"rule_summary" : "",
"rule_type" : "SQLPLAN",
"solution" : [
"1.使用连接查询",
"2.避免大的结果集"
],
"weight" : 0.1
}
{
"_id" : ObjectId("5b61644153cc7e049902d11d"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : 10.0,
"output_parms" : [
{
"parm_desc" : "CHECKSUM",
"parm_name" : "CHECKSUM"
},
{
"parm_desc" : "执行次数",
"parm_name" : "ts_cnt"
},
{
"parm_desc" : "平均执行时间",
"parm_name" : "query_time_avg"
},
{
"parm_desc" : "平均返回记录数",
"parm_name" : "rows_sent_avg"
},
{
"parm_desc" : "扫描命中率",
"parm_name" : "index_ratio"
}
],
"rule_complexity" : "simple",
"rule_cmd" : "db.planitem.find({\"schemas\":\"@schema_name@\",\"dependent\" : true}).forEach(function(x){db.sqlinfo.find({checksum:x.checksum}).forEach(function(y){db.@tmp@.save({\"checksum\" :y.checksum,\"ts_cnt\" :y.ts_cnt,\"query_time_avg\" :y.query_time_avg,\"rows_sent_avg\" :y.rows_sent_avg,\"index_ratio\" :y.index_ratio})})})",
"rule_desc" : "dependent",
"rule_name" : "DEPENDENT",
"rule_status" : "ON",
"rule_summary" : "",
"rule_type" : "SQLPLAN",
"solution" : [
"使用连接查询"
],
"weight" : 0.1
}
{
"_id" : ObjectId("5b61644153cc7e049902d120"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : 10.0,
"output_parms" : [
{
"parm_desc" : "CHECKSUM",
"parm_name" : "CHECKSUM"
},
{
"parm_desc" : "执行次数",
"parm_name" : "ts_cnt"
},
{
"parm_desc" : "平均执行时间",
"parm_name" : "query_time_avg"
},
{
"parm_desc" : "平均返回记录数",
"parm_name" : "rows_sent_avg"
},
{
"parm_desc" : "扫描命中率",
"parm_name" : "index_ratio"
}
],
"rule_complexity" : "simple",
"rule_cmd" : "db.planitem.find({\"schemas\":\"@schema_name@\",\"access_type\" : \"unique_subquery\"}).forEach(function(x){db.sqlinfo.find({checksum:x.checksum}).forEach(function(y){db.@tmp@.save({\"checksum\" :y.checksum,\"ts_cnt\" :y.ts_cnt,\"query_time_avg\" :y.query_time_avg,\"rows_sent_avg\" :y.rows_sent_avg,\"index_ratio\" :y.index_ratio})})})",
"rule_desc" : "unique_subquery",
"rule_name" : "UNIQUE_SUBQUERY",
"rule_status" : "ON",
"rule_summary" : "",
"rule_type" : "SQLPLAN",
"solution" : [
"子查询改写为表关联"
],
"weight" : 0.1
}
{
"_id" : ObjectId("5b61644153cc7e049902d121"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : 10.0,
"output_parms" : [
{
"parm_desc" : "CHECKSUM",
"parm_name" : "CHECKSUM"
},
{
"parm_desc" : "执行次数",
"parm_name" : "ts_cnt"
},
{
"parm_desc" : "平均执行时间",
"parm_name" : "query_time_avg"
},
{
"parm_desc" : "平均返回记录数",
"parm_name" : "rows_sent_avg"
},
{
"parm_desc" : "扫描命中率",
"parm_name" : "index_ratio"
}
],
"rule_complexity" : "simple",
"rule_cmd" : "db.planitem.find({\"schemas\":\"@schema_name@\",\"cacheable\" : false}).forEach(function(x){db.sqlinfo.find({checksum:x.checksum}).forEach(function(y){db.@tmp@.save({\"checksum\" :y.checksum,\"ts_cnt\" :y.ts_cnt,\"query_time_avg\" :y.query_time_avg,\"rows_sent_avg\" :y.rows_sent_avg,\"index_ratio\" :y.index_ratio})})})",
"rule_desc" : "cacheable",
"rule_name" : "CACHEABLE",
"rule_status" : "ON",
"rule_summary" : "",
"rule_type" : "SQLPLAN",
"solution" : [
"无后续补充"
],
"weight" : 0.1
}
{
"_id" : ObjectId("5b61644153cc7e049902d128"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : 10.0,
"output_parms" : [
{
"parm_desc" : "CHECKSUM",
"parm_name" : "CHECKSUM"
},
{
"parm_desc" : "扫描行数",
"parm_name" : "ROWS"
},
{
"parm_desc" : "执行次数",
"parm_name" : "ts_cnt"
},
{
"parm_desc" : "平均执行时间",
"parm_name" : "query_time_avg"
},
{
"parm_desc" : "平均返回记录数",
"parm_name" : "rows_sent_avg"
},
{
"parm_desc" : "扫描命中率",
"parm_name" : "index_ratio"
}
],
"rule_complexity" : "simple",
"rule_cmd" : "db.planitem.find({\"schemas\":\"@schema_name@\",\"access_type\" : \"ALL\",\"$or\": [{\"rows\" : {\"$gt\":1}}, {\"rows_examined_per_scan\": {\"$gt\":1}}],\"citem_type\":{\"$ne\":\"materialized_from_subquery\"}}).forEach(function(x){db.sqlinfo.find({checksum:x.checksum}).forEach(function(y){if(x.rows){rows=x.rows}else{rows=x.rows_examined_per_scan}db.@tmp@.save({\"checksum\" :y.checksum,\"ts_cnt\" :y.ts_cnt,\"query_time_avg\" :y.query_time_avg,\"rows_sent_avg\" :y.rows_sent_avg,\"index_ratio\" :y.index_ratio,\"rows\":rows})})})",
"rule_desc" : "全表扫描",
"rule_name" : "TABLE_FULL_SCAN",
"rule_status" : "ON",
"rule_summary" : "大表全表扫描,行数超过阀值,扫描了多余的数据,建议使用索引来避免",
"rule_type" : "SQLPLAN",
"solution" : [
"1.缺索引评估创建索引",
"2.取max、min值评估创建索引",
"3.索引失效重建索引,分区表维护记得维护索引",
"4.对条件字段使用函数或表达式a.函数、表达式放到等于号的右边b.创建函数索引(下策)",
"5.出现隐式转换a.不同类型的谓词匹配先显式转换b.表定义根据数据选择正确的数据类型",
"6.使用不等运算符<>!=做查询条件a.尽量少用不等判断;b.如果列值是连续,可把否定操作更改为两个区间;c.如果列值不多,可用inlist枚举其他所有值",
"7.模糊匹配%a%,%a建议精确匹配",
"8.sql逻辑,比如最大值,改用窗口函数",
"9.弱选择sql,返回结果集较大建议a.添加更多的谓词减少数据的访问,比如时间b.改造分区表c.使用覆盖索引",
"10.统计信息不准确数据批量加载程序触发收集统计信息"
],
"weight" : 0.1
}
{
"_id" : ObjectId("5b61644153cc7e049902d129"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : 10.0,
"output_parms" : [
{
"parm_desc" : "CHECKSUM",
"parm_name" : "CHECKSUM"
},
{
"parm_desc" : "执行次数",
"parm_name" : "ts_cnt"
},
{
"parm_desc" : "平均执行时间",
"parm_name" : "query_time_avg"
},
{
"parm_desc" : "平均返回记录数",
"parm_name" : "rows_sent_avg"
},
{
"parm_desc" : "扫描命中率",
"parm_name" : "index_ratio"
}
],
"rule_complexity" : "simple",
"rule_cmd" : "db.planitem.find({\"schemas\":\"@schema_name@\",\"using_temporary_table\" : true}).forEach(function(x){db.sqlinfo.find({checksum:x.checksum}).forEach(function(y){db.@tmp@.save({\"checksum\" :y.checksum,\"ts_cnt\" :y.ts_cnt,\"query_time_avg\" :y.query_time_avg,\"rows_sent_avg\" :y.rows_sent_avg,\"index_ratio\" :y.index_ratio})})})",
"rule_desc" : "临时表排序",
"rule_name" : "USING_TEMPORARY_TABLE",
"rule_status" : "ON",
"rule_summary" : "",
"rule_type" : "SQLPLAN",
"solution" : [
"避免大排序"
],
"weight" : 0.1
}
{
"_id" : ObjectId("5b61644153cc7e049902d12a"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : 10.0,
"output_parms" : [
{
"parm_desc" : "CHECKSUM",
"parm_name" : "CHECKSUM"
},
{
"parm_desc" : "执行次数",
"parm_name" : "ts_cnt"
},
{
"parm_desc" : "平均执行时间",
"parm_name" : "query_time_avg"
},
{
"parm_desc" : "平均返回记录数",
"parm_name" : "rows_sent_avg"
},
{
"parm_desc" : "扫描命中率",
"parm_name" : "index_ratio"
}
],
"rule_complexity" : "simple",
"rule_cmd" : "db.planitem.find({\"schemas\":\"@schema_name@\",\"using_filesort\" : true}).forEach(function(x){db.sqlinfo.find({checksum:x.checksum}).forEach(function(y){db.@tmp@.save({\"checksum\" :y.checksum,\"ts_cnt\" :y.ts_cnt,\"query_time_avg\" :y.query_time_avg,\"rows_sent_avg\" :y.rows_sent_avg,\"index_ratio\" :y.index_ratio})})})",
"rule_desc" : "磁盘排序",
"rule_name" : "USING_FILESORT",
"rule_status" : "ON",
"rule_summary" : "",
"rule_type" : "SQLPLAN",
"solution" : [
"避免大排序"
],
"weight" : 0.1
}
{
"_id" : ObjectId("5b61644153cc7e049902d12b"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : 10.0,
"output_parms" : [
{
"parm_desc" : "CHECKSUM",
"parm_name" : "CHECKSUM"
},
{
"parm_desc" : "执行次数",
"parm_name" : "ts_cnt"
},
{
"parm_desc" : "平均执行时间",
"parm_name" : "query_time_avg"
},
{
"parm_desc" : "平均返回记录数",
"parm_name" : "rows_sent_avg"
},
{
"parm_desc" : "扫描命中率",
"parm_name" : "index_ratio"
}
],
"rule_complexity" : "simple",
"rule_cmd" : "db.planitem.find({\"schemas\":\"@schema_name@\",\"access_type\" : \"fulltext\"}).forEach(function(x){db.sqlinfo.find({checksum:x.checksum}).forEach(function(y){db.@tmp@.save({\"checksum\" :y.checksum,\"ts_cnt\" :y.ts_cnt,\"query_time_avg\" :y.query_time_avg,\"rows_sent_avg\" :y.rows_sent_avg,\"index_ratio\" :y.index_ratio})})})",
"rule_desc" : "fulltext",
"rule_name" : "FULLTEXT",
"rule_status" : "ON",
"rule_summary" : "",
"rule_type" : "SQLPLAN",
"solution" : [
"不建议使用全文索引,大字段使用外部存储方式"
],
"weight" : 0.1
}
{
"_id" : ObjectId("5b61644153cc7e049902d12c"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : 10.0,
"output_parms" : [
{
"parm_desc" : "CHECKSUM",
"parm_name" : "CHECKSUM"
},
{
"parm_desc" : "执行次数",
"parm_name" : "ts_cnt"
},
{
"parm_desc" : "平均执行时间",
"parm_name" : "query_time_avg"
},
{
"parm_desc" : "平均返回记录数",
"parm_name" : "rows_sent_avg"
},
{
"parm_desc" : "扫描命中率",
"parm_name" : "index_ratio"
}
],
"rule_complexity" : "simple",
"rule_cmd" : "db.planitem.find({\"schemas\":\"@schema_name@\",\"access_type\" : \"index_merge\"}).forEach(function(x){db.sqlinfo.find({checksum:x.checksum}).forEach(function(y){db.@tmp@.save({\"checksum\" :y.checksum,\"ts_cnt\" :y.ts_cnt,\"query_time_avg\" :y.query_time_avg,\"rows_sent_avg\" :y.rows_sent_avg,\"index_ratio\" :y.index_ratio})})})",
"rule_desc" : "index_merge",
"rule_name" : "INDEX_MERGE",
"rule_status" : "ON",
"rule_summary" : "",
"rule_type" : "SQLPLAN",
"solution" : [
"创建复合索引"
],
"weight" : 0.1
}
{
"_id" : ObjectId("5b61644153cc7e049902d12e"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : 10.0,
"output_parms" : [
{
"parm_desc" : "CHECKSUM",
"parm_name" : "CHECKSUM"
},
{
"parm_desc" : "执行次数",
"parm_name" : "ts_cnt"
},
{
"parm_desc" : "平均执行时间",
"parm_name" : "query_time_avg"
},
{
"parm_desc" : "平均返回记录数",
"parm_name" : "rows_sent_avg"
},
{
"parm_desc" : "扫描命中率",
"parm_name" : "index_ratio"
}
],
"rule_complexity" : "simple",
"rule_cmd" : "db.planitem.find({\"schemas\":\"@schema_name@\",\"citem_type\" : \"nested_loop\",\"citem.3\":{\"$exists\":1}}).forEach(function(x){db.sqlinfo.find({checksum:x.checksum}).forEach(function(y){db.@tmp@.save({\"checksum\" :y.checksum,\"ts_cnt\" :y.ts_cnt,\"query_time_avg\" :y.query_time_avg,\"rows_sent_avg\" :y.rows_sent_avg,\"index_ratio\" :y.index_ratio})})})",
"rule_desc" : "multi_tab_join",
"rule_name" : "MULTI_TAB_JOIN",
"rule_status" : "ON",
"rule_summary" : "",
"rule_type" : "SQLPLAN",
"solution" : [
"sql逻辑改写,减少表关联"
],
"weight" : 0.1
}
{
"_id" : ObjectId("5b61644153cc7e049902d133"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : 10.0,
"output_parms" : [
{
"parm_desc" : "CHECKSUM",
"parm_name" : "CHECKSUM"
},
{
"parm_desc" : "执行次数",
"parm_name" : "ts_cnt"
},
{
"parm_desc" : "平均执行时间",
"parm_name" : "query_time_avg"
},
{
"parm_desc" : "平均返回记录数",
"parm_name" : "rows_sent_avg"
},
{
"parm_desc" : "扫描命中率",
"parm_name" : "index_ratio"
}
],
"rule_complexity" : "simple",
"rule_cmd" : "db.sqlinfo.find({\"sqlplan_json.complex\":1}).forEach(function(y){db.@tmp@.save({\"checksum\" :y.checksum,\"ts_cnt\" :y.ts_cnt,\"query_time_avg\" :y.query_time_avg,\"rows_sent_avg\" :y.rows_sent_avg,\"index_ratio\" :y.index_ratio})})",
"rule_desc" : "complex_sql",
"rule_name" : "COMPLEX_SQL",
"rule_status" : "ON",
"rule_summary" : "",
"rule_type" : "SQLPLAN",
"solution" : [
"sql过于复杂,无法得到json格式执行计划,建议在逻辑和业务上避免此类复杂sql"
],
"weight" : 0.1
}
{
"_id" : ObjectId("5b61644153cc7e049902d134"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : 10.0,
"output_datas" : [
{
"parm_desc" : "CHECKSUM",
"parm_name" : "CHECKSUM"
},
{
"parm_desc" : "执行次数",
"parm_name" : "ts_cnt"
},
{
"parm_desc" : "平均执行时间",
"parm_name" : "query_time_avg"
},
{
"parm_desc" : "平均返回记录数",
"parm_name" : "rows_sent_avg"
},
{
"parm_desc" : "扫描命中率",
"parm_name" : "index_ratio"
},
{
"parm_desc" : "锁定时间总和",
"parm_name" : "Lock_time_sum"
}
],
"rule_complexity" : "simple",
"rule_cmd" : "db.sqlinfo.find({\"Lock_time_sum\" : {$gt:60}}).forEach(function(y){db.@tmp@.save({\"checksum\" :y.checksum,\"ts_cnt\" :y.ts_cnt,\"query_time_avg\" :y.query_time_avg,\"rows_sent_avg\" :y.rows_sent_avg,\"index_ratio\" :y.index_ratio, \"Lock_time_sum\" :y.Lock_time_sum})})",
"rule_desc" : "Lock_time_sum",
"rule_name" : "LOCK_TIME_SUM",
"rule_status" : "ON",
"rule_summary" : "锁定时间过长",
"rule_type" : "SQLSTAT",
"solution" : [
"对sql消耗资源评估是否合理,能否优化"
],
"weight" : 0.1
}
{
"_id" : ObjectId("5b61644153cc7e049902d135"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : 10.0,
"output_datas" : [
{
"parm_desc" : "CHECKSUM",
"parm_name" : "CHECKSUM"
},
{
"parm_desc" : "执行次数",
"parm_name" : "ts_cnt"
},
{
"parm_desc" : "平均执行时间",
"parm_name" : "query_time_avg"
},
{
"parm_desc" : "平均返回记录数",
"parm_name" : "rows_sent_avg"
},
{
"parm_desc" : "扫描命中率",
"parm_name" : "index_ratio"
},
{
"parm_desc" : "锁定时间总和",
"parm_name" : "Lock_time_sum"
}
],
"rule_complexity" : "simple",
"rule_cmd" : "db.sqlinfo.find({\"index_ratio\" : {$gt:10000}}).forEach(function(y){db.@tmp@.save({\"checksum\" :y.checksum,\"ts_cnt\" :y.ts_cnt,\"query_time_avg\" :y.query_time_avg,\"rows_sent_avg\" :y.rows_sent_avg,\"index_ratio\" :y.index_ratio, \"Lock_time_sum\" :y.Lock_time_sum})})",
"rule_desc" : "index_ratio",
"rule_name" : "INDEX_RATIO",
"rule_status" : "ON",
"rule_summary" : "扫描命中率过低",
"rule_type" : "SQLSTAT",
"solution" : [
"对sql消耗资源评估是否合理,能否优化"
],
"weight" : 0.1
}
{
"_id" : ObjectId("5b61644153cc7e049902d13e"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_complexity" : "simple",
"rule_cmd" : "(cross join)|(outer join)",
"rule_desc" : "存在全连接或外连接,cross join或outer join情况",
"rule_name" : "BAD_JOIN",
"rule_status" : "ON",
"rule_summary" : "存在全连接或外连接,cross join或outer join情况",
"rule_type" : "TEXT",
"solution" : [
"改写为innerjoin"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d13f"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_complexity" : "complex",
"rule_cmd" : "default",
"rule_desc" : "delete或update中必须出现where子句,防止出现意外的全部删除或更新动作",
"rule_name" : "DML_ALLDATA",
"rule_status" : "ON",
"rule_summary" : "delete或update中必须出现where子句,防止出现意外的全部删除或更新动作",
"rule_type" : "TEXT",
"solution" : [
"1.建议加where条件",
"2.全表删除用truncate"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d146"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
{
"parm_desc" : "or个数",
"parm_name" : "or_num",
"parm_value" : NumberInt(5),
"parm_unit" : ""
}
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_desc" : "多个过滤条件通过or连接",
"rule_complexity" : "complex",
"rule_cmd" : "default",
"rule_name" : "TOOMANY_OR",
"rule_status" : "ON",
"rule_summary" : "多个过滤条件通过or连接,防止优化器出现选择异常",
"rule_type" : "TEXT",
"solution" : [
"改用临时表存入变量"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d147"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_complexity" : "simple",
"rule_cmd" : "like .\\%",
"rule_desc" : "谓词条件使用like %xxx,无法使用索引",
"rule_name" : "LIKE_UNINDEX",
"rule_status" : "ON",
"rule_summary" : "谓词条件使用like %xxx,无法使用索引",
"rule_type" : "TEXT",
"solution" : [
"从业务角度出发,分析是否可使用精确运算符或类似like'xx%'"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d14b"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_desc" : "select段出现子查询",
"rule_name" : "SUBQUERY_SELECT",
"rule_complexity" : "complex",
"rule_cmd" : "default",
"rule_status" : "OFF",
"rule_summary" : "select段出现子查询",
"rule_type" : "TEXT",
"solution" : [
"改写为表关联"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d14d"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
{
"parm_desc" : "inlist元素个数",
"parm_name" : "in_list_num",
"parm_value" : NumberInt(20),
"parm_unit" : ""
}
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_desc" : "IN List元素过多",
"rule_name" : "TOOMANY_IN_LIST",
"rule_complexity" : "complex",
"rule_cmd" : "default",
"rule_status" : "ON",
"rule_summary" : "IN List元素过多",
"rule_type" : "TEXT",
"solution" : [
"改用临时表存入变量"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d14e"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
{
"parm_desc" : "SQL字符数量",
"parm_name" : "char_num",
"parm_value" : NumberInt(1000),
"parm_unit" : ""
}
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_desc" : "SQL文本过长",
"rule_name" : "LONG_TEXT",
"rule_complexity" : "complex",
"rule_cmd" : "default",
"rule_status" : "ON",
"rule_summary" : "SQL文本过长",
"rule_type" : "TEXT",
"solution" : [
"sql改写为精简语句"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d14f"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_complexity" : "complex",
"rule_cmd" : "default",
"rule_desc" : "重复查询子句",
"rule_name" : "SUBQUERY_REP",
"rule_status" : "ON",
"rule_summary" : "禁止使用重复的查询子句,应使用with as替换子句(仅限Oracle)来提升SQL执行效率",
"rule_type" : "TEXT",
"solution" : [
"1.withas",
"2.改写sql避免重复查询"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d150"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_desc" : "where段出现子查询",
"rule_name" : "SUBQUERY_WHERE",
"rule_complexity" : "complex",
"rule_cmd" : "",
"rule_status" : "OFF",
"rule_summary" : "where段出现子查询",
"rule_type" : "TEXT",
"solution" : [
"改写为表关联"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d152"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_desc" : "谓词中存在负向操作符,!=,<>,!<,!>,not exists,not",
"rule_complexity" : "simple",
"rule_cmd" : "(!=)|(<>)|(!>)|(!<)",
"rule_name" : "WHERE_NOT",
"rule_status" : "ON",
"rule_summary" : "谓词中存在负向操作符,!=,<>,!<,!>,not exists,not",
"rule_type" : "TEXT",
"solution" : [
"1.如果列值是连续,可把否定操作,更改为两个区间",
"2.不建议使用不等值运算"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d154"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_complexity" : "simple",
"rule_cmd" : "(select \\*)|(select .*\\.\\*)",
"rule_desc" : "禁止使用select *,必须明确选择所需的列。",
"rule_name" : "SELECT_ANY",
"rule_status" : "ON",
"rule_summary" : "禁止使用select *,必须明确选择所需的列",
"rule_type" : "TEXT",
"solution" : [
"使用明确的列"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d156"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_complexity" : "complex",
"rule_cmd" : "default",
"rule_desc" : "having段出现子查询",
"rule_name" : "SUBQUERY_HAVING",
"rule_status" : "OFF",
"rule_summary" : "having段出现子查询",
"rule_type" : "TEXT",
"solution" : [
"改写为表关联"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d157"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_desc" : "delete或update中出现order by子句,防止删除或更新过程中出现不必要的排序",
"rule_name" : "DML_SORT",
"rule_complexity" : "simple",
"rule_cmd" : "(\\s)?((update )|(delete )).*order by",
"rule_status" : "ON",
"rule_summary" : "delete或update中出现order by子句,防止删除或更新过程中出现不必要的排序",
"rule_type" : "TEXT",
"solution" : [
"dml操作不需排序"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d159"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_desc" : "出现union.防止出现不必要的排序动作",
"rule_name" : "UNION",
"rule_complexity" : "complex",
"rule_cmd" : "default",
"rule_status" : "ON",
"rule_summary" : "出现union,防止出现不必要的排序动作",
"rule_type" : "TEXT",
"solution" : [
"改写unionall和sql逻辑中去重"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d15a"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_desc" : "查询字段引用函数",
"rule_complexity" : "simple",
"rule_cmd" : "\\)\\s?[<>=]{1,2}",
"rule_name" : "WHERE_FUNC",
"rule_status" : "ON",
"rule_summary" : "禁止在查询字段中引用函数",
"rule_type" : "TEXT",
"solution" : [
"1.函数写在表达式右边",
"2.应用程序实现函数功能"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d15b"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : NumberInt(20),
"output_parms" : [
],
"rule_desc" : "from段出现子查询",
"rule_complexity" : "complex",
"rule_cmd" : "default",
"rule_name" : "SUBQUERY_FROM",
"rule_status" : "OFF",
"rule_summary" : "from段出现子查询",
"rule_type" : "TEXT",
"solution" : [
"改写为表关联"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d15e"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
],
"max_score" : NumberInt(6),
"output_parms" : [
{
"parm_desc" : "表名",
"parm_name" : "title1"
},
{
"parm_desc" : "字段名",
"parm_name" : "title2"
},
{
"parm_desc" : "数据类型",
"parm_name" : "title3"
}
],
"rule_desc" : "大对象字段将影响存取性能、耗费较多空间,建议在数据库之外存储。",
"rule_complexity" : "simple",
"rule_cmd" : "SELECT TABLE_NAME,column_name , DATA_TYPE FROM information_schema.COLUMNS where TABLE_SCHEMA='@username@' and DATA_TYPE in ('blob','mediumblob','longblob','text','mediumblob','longtext') order by table_name",
"rule_name" : "EXIST_LOB_COLUMN",
"rule_status" : "ON",
"rule_summary" : "存在大对象字段",
"rule_type" : "OBJ",
"solution" : [
"建议在数据库外部进行存储大字段"
],
"weight" : NumberInt(2)
}
{
"_id" : ObjectId("5b61644153cc7e049902d15f"),
"db_type" : "mysql",
"exclude_obj_type" : "",
"input_parms" : [
{
"parm_desc" : "提取做正则判断记录数上限",
"parm_name" : "num_row",
"parm_value" : NumberInt(10000),
"parm_unit" : ""
}