
目前有很多专业的小程序开发公司,主要分为以下两类
第一种:卖模板的小程序公司
优点是:价格低,5000-10000元,适合对小程序功能没太多要求,急需上线的企业
缺点是:这种模板“一键生成”的小程序,需要按年续费,并非永久拥有自己的小程序;这种模板小程序也无法开发个性化功能,后期无法实现二次开发。
第二种:定制开发的小程序开发公司
优点是:独一无二的,专为你的企业或者店面定制的,功能你来定,要求你来定,后期修改BUG方便,二次开发添加功能也很方便,最重要的是永久使用权!
缺点是:价格较高,一般一万到十几万不等,具体看功能需求了
最后总结,具体选择模板小程序还是定制开发小程序,要看公司的具体需求和预算了
在开始演示之前,我们先介绍下两个概念。
概念一,数据的可选择性基数,也就是常说的cardinality值。
查询优化器在生成各种执行计划之前,得先从统计信息中取得相关数据,这样才能估算每步 *** 作所涉及到的记录数,而这个相关数据就是cardinality。简单来说,就是每个值在每个字段中的唯一值分布状态。
比如表t1有100行记录,其中一列为f1。f1中唯一值的个数可以是100个,也可以是1个,当然也可以是1到100之间的任何一个数字。这里唯一值越的多少,就是这个列的可选择基数。
那看到这里我们就明白了,为什么要在基数高的字段上建立索引,而基数低的的字段建立索引反而没有全表扫描来的快。当然这个只是一方面,至于更深入的探讨就不在我这篇探讨的范围了。
概念二,关于HINT的使用。
这里我来说下HINT是什么,在什么时候用。
HINT简单来说就是在某些特定的场景下人工协助MySQL优化器的工作,使她生成最优的执行计划。一般来说,优化器的执行计划都是最优化的,不过在某些特定场景下,执行计划可能不是最优化。
比如:表t1经过大量的频繁更新 *** 作,(UPDATE,DELETE,INSERT),cardinality已经很不准确了,这时候刚好执行了一条SQL,那么有可能这条SQL的执行计划就不是最优的。为什么说有可能呢?
来看下具体演示
譬如,以下两条SQL,
A:
select from t1 where f1 = 20;B:
select from t1 where f1 = 30;如果f1的值刚好频繁更新的值为30,并且没有达到MySQL自动更新cardinality值的临界值或者说用户设置了手动更新又或者用户减少了sample page等等,那么对这两条语句来说,可能不准确的就是B了。
这里顺带说下,MySQL提供了自动更新和手动更新表cardinality值的方法,因篇幅有限,需要的可以查阅手册。
那回到正题上,MySQL 80 带来了几个HINT,我今天就举个index_merge的例子。
示例表结构:
mysql> desc t1;+------------+--------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+------------+--------------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment || rank1 | int(11) | YES | MUL | NULL | || rank2 | int(11) | YES | MUL | NULL | || log_time | datetime | YES | MUL | NULL | || prefix_uid | varchar(100) | YES | | NULL | || desc1 | text | YES | | NULL | || rank3 | int(11) | YES | MUL | NULL | |+------------+--------------+------+-----+---------+----------------+7 rows in set (000 sec)表记录数:
mysql> select count() from t1;+----------+| count() |+----------+| 32768 |+----------+1 row in set (001 sec)这里我们两条经典的SQL:
SQL C:
select from t1 where rank1 = 1 or rank2 = 2 or rank3 = 2;SQL D:
select from t1 where rank1 =100 and rank2 =100 and rank3 =100;表t1实际上在rank1,rank2,rank3三列上分别有一个二级索引。
那我们来看SQL C的查询计划。
显然,没有用到任何索引,扫描的行数为32034,cost为324365。
mysql> explain format=json select from t1 where rank1 =1 or rank2 = 2 or rank3 = 2\G 1 row EXPLAIN: { "query_block": { "select_id": 1, "cost_info": { "query_cost": "324365" }, "table": { "table_name": "t1", "access_type": "ALL", "possible_keys": [ "idx_rank1", "idx_rank2", "idx_rank3" ], "rows_examined_per_scan": 32034, "rows_produced_per_join": 115, "filtered": "036", "cost_info": { "read_cost": "323207", "eval_cost": "1158", "prefix_cost": "324365", "data_read_per_join": "49K" }, "used_columns": [ "id", "rank1", "rank2", "log_time", "prefix_uid", "desc1", "rank3" ], "attached_condition": "((`ytt``t1``rank1` = 1) or (`ytt``t1``rank2` = 2) or (`ytt``t1``rank3` = 2))" } }}1 row in set, 1 warning (000 sec)我们加上hint给相同的查询,再次看看查询计划。
这个时候用到了index_merge,union了三个列。扫描的行数为1103,cost为44109,明显比之前的快了好几倍。
mysql> explain format=json select /+ index_merge(t1) / from t1 where rank1 =1 or rank2 = 2 or rank3 = 2\G 1 row EXPLAIN: { "query_block": { "select_id": 1, "cost_info": { "query_cost": "44109" }, "table": { "table_name": "t1", "access_type": "index_merge", "possible_keys": [ "idx_rank1", "idx_rank2", "idx_rank3" ], "key": "union(idx_rank1,idx_rank2,idx_rank3)", "key_length": "5,5,5", "rows_examined_per_scan": 1103, "rows_produced_per_join": 1103, "filtered": "10000", "cost_info": { "read_cost": "33079", "eval_cost": "11030", "prefix_cost": "44109", "data_read_per_join": "473K" }, "used_columns": [ "id", "rank1", "rank2", "log_time", "prefix_uid", "desc1", "rank3" ], "attached_condition": "((`ytt``t1``rank1` = 1) or (`ytt``t1``rank2` = 2) or (`ytt``t1``rank3` = 2))" } }}1 row in set, 1 warning (000 sec)我们再看下SQL D的计划:
不加HINT,
mysql> explain format=json select from t1 where rank1 =100 and rank2 =100 and rank3 =100\G 1 row EXPLAIN: { "query_block": { "select_id": 1, "cost_info": { "query_cost": "53434" }, "table": { "table_name": "t1", "access_type": "ref", "possible_keys": [ "idx_rank1", "idx_rank2", "idx_rank3" ], "key": "idx_rank1", "used_key_parts": [ "rank1" ], "key_length": "5", "ref": [ "const" ], "rows_examined_per_scan": 555, "rows_produced_per_join": 0, "filtered": "007", "cost_info": { "read_cost": "47884", "eval_cost": "004", "prefix_cost": "53434", "data_read_per_join": "176" }, "used_columns": [ "id", "rank1", "rank2", "log_time", "prefix_uid", "desc1", "rank3" ], "attached_condition": "((`ytt``t1``rank3` = 100) and (`ytt``t1``rank2` = 100))" } }}1 row in set, 1 warning (000 sec)加了HINT,
mysql> explain format=json select /+ index_merge(t1)/ from t1 where rank1 =100 and rank2 =100 and rank3 =100\G 1 row EXPLAIN: { "query_block": { "select_id": 1, "cost_info": { "query_cost": "523" }, "table": { "table_name": "t1", "access_type": "index_merge", "possible_keys": [ "idx_rank1", "idx_rank2", "idx_rank3" ], "key": "intersect(idx_rank1,idx_rank2,idx_rank3)", "key_length": "5,5,5", "rows_examined_per_scan": 1, "rows_produced_per_join": 1, "filtered": "10000", "cost_info": { "read_cost": "513", "eval_cost": "010", "prefix_cost": "523", "data_read_per_join": "440" }, "used_columns": [ "id", "rank1", "rank2", "log_time", "prefix_uid", "desc1", "rank3" ], "attached_condition": "((`ytt``t1``rank3` = 100) and (`ytt``t1``rank2` = 100) and (`ytt``t1``rank1` = 100))" } }}1 row in set, 1 warning (000 sec)对比下以上两个,加了HINT的比不加HINT的cost小了100倍。
总结下,就是说表的cardinality值影响这张的查询计划,如果这个值没有正常更新的话,就需要手工加HINT了。相信MySQL未来的版本会带来更多的HINT。
数据量比较大的访问速度慢问题,就目前来说,我遇到的解决方法有一些,首先尽量不使用select ,因为数据库在进行查询时会把对应的列进行解析,会使得数据库的访问速度变慢,查询时应该选择需要的列;另外在查询时需要在关键列上建立索引,索引是提高访问数据库速度的最重要的手段,一般访问速度慢的问题中,90%可以使用建立索引来解决,具体怎么建立索引还请楼主自己查看相关资料;再一个就是及时对表进行数据分析,分析过的表能够自己选择合适的索引,使得查询性能在一定程度上得到提高(但是数据库自己选择的执行路径也不一定都是正确的,这一点需要具体问题具体分析)。
以上就是关于微信小程序云开发关于数据库读取延迟问题的解决全部的内容,包括:微信小程序云开发关于数据库读取延迟问题的解决、求高手优化MySQL数据库,数据库反应太慢。、怎么样解决数据库中的数据量比较大时访问慢的问题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)