Oracle中Hint深入理解
Hint概述
基于代价的优化器是很聪明的,在绝大多数情况下它会选择正确的优化器,减轻了DBA的负担。但有时它也聪明反被聪明误,选择了很差的执行计划,使某个语句的执行变得奇慢无比。
此时就需要DBA进行人为的干预,告诉优化器使用我们指定的存取路径或连接类型生成执行计划,从
而使语句高效的运行。例如,如果我们认为对于一个特定的语句,执行全表扫描要比执行索引扫描更有效,则我们就可以指示优化器使用全表扫描。在Oracle
中,是通过为语句添加 Hints(提示)来实现干预优化器优化的目的。
不建议在代码中使用hint,在代码使用hint使得CBO无法根据实际的数据状态选择正确的执行计划。毕竟
数据是不断变化的,
10g以后的CBO也越来越完善,大多数情况下我们该让Oracle自行决定采用什么执行计划。
Oracle Hints是一种机制,用来告诉优化器按照我们的告诉它的方式生成执行计划。我们可以用Oracle Hints来实现:
1) 使用的优化器的类型
2) 基于代价的优化器的优化目标,是all_rows还是first_rows。
3) 表的访问路径,是全表扫描,还是索引扫描,还是直接利用rowid。
4) 表之间的连接类型
5) 表之间的连接顺序
6) 语句的并行程度
除了”RULE”提示外,一旦使用的别的提示,语句就会自动的改为使用CBO优化器,此时如果你的数据字典中没有统计数据,就会使用缺省的统计数据。所以建议大家如果使用CBO或Hints提示,则最好对表和索引进行定期的分析。
如何使用Hints:
Hints只应用在它们所在sql语句块(statement
block,由select、update、delete关键字标识)上,对其它SQL语句或语句的其它部分没有影响。如:对于使用union操作的2个sql语句,如果只在一个sql语句上有Hints,则该Hints不会影响另一个sql语句。
我们可以使用注释(comment)来为一个语句添加Hints,一个语句块只能有一个注释,而且注释只能放在SELECT, UPDATE, or DELETE关键字的后面
使用Oracle Hints的语法:
{DELETE|INSERT|SELECT|UPDATE} /*+ hint [text] [hint[text]]... */
or
{DELETE|INSERT|SELECT|UPDATE} --+ hint [text] [hint[text]]...
注解:
1) DELETE、INSERT、SELECT和UPDATE是标识一个语句块开始的关键字,包含提示的注释只能出现在这些关键字的后面,否则提示无效。
2) “+”号表示该注释是一个Hints,该加号必须立即跟在”/*”的后面,中间不能有空格。
3) hint是下面介绍的具体提示之一,如果包含多个提示,则每个提示之间需要用一个或多个空格隔开。
4) text 是其它说明hint的注释性文本
5)使用表别名。如果在查询中指定了表别名,那么提示必须也使用表别名。例如:select /*+ index(e,dept_idx) */ * from emp e;
6)不要在提示中使用模式名称:如果在提示中指定了模式的所有者,那么提示将被忽略。例如:
select /*+ index(scott.emp,dept_idx) */ * from emp
注意:如果你没有正确的指定Hints,Oracle将忽略该Hints,并且不会给出任何错误。
hint被忽略
如果CBO认为使用hint会导致错误的结果时,hint将被忽略,详见下例
SQL> select /*+ index(t t_ind) */ count(*) from t;
Execution Plan
----------------------------------------------------------
Plan hash value: 2966233522
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 57 (2)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| T | 50366 | 57 (2)| 00:00:01 |
-------------------------------------------------------------------
因为我们是对记录求总数,且我们并没有在建立索引时指定不能为空,索引如果CBO选择在索引上进行count时,但索引字段上的值为空时,结果将不准确,故CBO没有选择索引。
SQL> select /*+ index(t t_ind) */ count(id) from t;
Execution Plan
----------------------------------------------------------
Plan hash value: 646498162
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 5 | 285 (1)| 00:00:04 |
| 1 | SORT AGGREGATE | | 1 | 5 | | |
| 2 | INDEX FULL SCAN| T_IND | 50366 | 245K| 285 (1)| 00:00:04 |
--------------------------------------------------------------------------
因为我们只对id进行count,这个动作相当于count索引上的所有id值,这个操作和对表上的id字段进行count是一样的(组函数会忽略null值)
Hint的具体用法
和优化器相关的hint
1、/*+ ALL_ROWS */
表明对语句块选择基于开销的优化方法,并获得最佳吞吐量,使资源消耗最小化.
SELECT /*+ ALL+_ROWS*/ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO='SCOTT';
2、/*+ FIRST_ROWS(n) */
表明对语句块选择基于开销的优化方法,并获得最佳响应时间,使资源消耗最小化.
SELECT /*+FIRST_ROWS(20) */ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO='SCOTT';
3、/*+ RULE*/
表明对语句块选择基于规则的优化方法.
SELECT /*+ RULE */ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO='SCOTT';
和访问路径相关的hint
1、/*+ FULL(TABLE)*/
表明对表选择全局扫描的方法.
SELECT /*+FULL(A)*/ EMP_NO,EMP_NAM FROM BSEMPMS A WHERE EMP_NO='SCOTT';
2、/*+ INDEX(TABLE INDEX_NAME) */
表明对表选择索引的扫描方法.
SELECT /*+INDEX(BSEMPMS SEX_INDEX) */ * FROM BSEMPMS WHERE SEX='M';
5、/*+ INDEX_ASC(TABLE INDEX_NAME)*/
表明对表选择索引升序的扫描方法.
SELECT /*+INDEX_ASC(BSEMPMS PK_BSEMPMS) */ * FROM BSEMPMS WHERE DPT_NO='SCOTT';
6、/*+ INDEX_COMBINE*/
为指定表选择位图访问路经,如果INDEX_COMBINE中没有提供作为参数的索引,将选择出位图索引的布尔组合方式.
SELECT /*+INDEX_COMBINE(BSEMPMS SAL_BMI HIREDATE_BMI) */ * FROM BSEMPMS
WHERE SAL<5000000 AND HIREDATE
7、/*+ INDEX_JOIN(TABLE INDEX_NAME1 INDEX_NAME2) */
当谓词中引用的列都有索引的时候,可以通过指定采用索引关联的方式,来访问数据
select /*+ index_join(t t_ind t_bm) */ id from t where id=100 and object_name='EMPLOYEES'
8、/*+ INDEX_DESC(TABLE INDEX_NAME)*/
表明对表选择索引降序的扫描方法.
SELECT /*+INDEX_DESC(BSEMPMS PK_BSEMPMS) */ *
FROM BSEMPMS WHERE DPT_NO='SCOTT';
9、/*+ INDEX_FFS(TABLE INDEX_NAME) */
对指定的表执行快速全索引扫描,而不是全表扫描的办法.
SELECT /* + INDEX_FFS(BSEMPMS IN_EMPNAM)*/ * FROM BSEMPMS WHERE DPT_NO='TEC305';
10、/*+ INDEX_SS(T T_IND) */
从9i开始,oracle引入了这种索引访问方式。当在一个联合索引中,某些谓词条件并不在联合索引的第一列时,可以通过Index Skip Scan来访问索引获得数据。当联合索引第一列的唯一值个数很少时,使用这种方式比全表扫描效率高。
SQL> create table t as select 1 id,object_name from dba_objects;
Table created.
SQL> insert into t select 2,object_name from dba_objects;
50366 rows created.
SQL> insert into t select 3,object_name from dba_objects;
50366 rows created.
SQL> insert into t select 4,object_name from dba_objects;
50366 rows created.
SQL> commit;
Commit complete.
SQL> create index t_ind on t(id,object_name);
Index created.
SQL> exec dbms_stats.gather_table_stats('HR','T',cascade=>true);
PL/SQL procedure successfully completed.
执行全表扫描
SQL> select /*+ full(t) */ * from t where object_name='EMPLOYEES';
6 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1601196873
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 | 135 | 215 (3)| 00:00:03 |
|* 1 | TABLE ACCESS FULL| T | 5 | 135 | 215 (3)| 00:00:03 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_NAME"='EMPLOYEES')
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
942 consistent gets
0 physical reads
0 redo size
538 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
6 rows processed
不采用hint
SQL> select * from t where object_name='EMPLOYEES';
6 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2869677071
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 | 135 | 5 (0)| 00:00:01 |
|* 1 | INDEX SKIP SCAN | T_IND | 5 | 135 | 5 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("OBJECT_NAME"='EMPLOYEES')
filter("OBJECT_NAME"='EMPLOYEES')
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
17 consistent gets
1 physical reads
0 redo size
538 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
6 rows processed
当全表扫描扫描了942个块,联合索引只扫描了17个数据块。可以看到联合索引的第一个字段的值重复率很高时,即使谓词中没有联合索引的第一个字段,依然会使用index_ss方式,效率远远高于全表扫描效率。但当
第一个字段的值重复率很低时,使用
index_ss的效率要低于
全表扫描,读者可以自行实验
和表的关联相关的hint
/*+ leading(table_1,table_2) */
在多表关联查询中,指定哪个表作为驱动表,即告诉优化器首先要访问哪个表上的数据。
select /*+ leading(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ order */
让Oracle根据from后面表的顺序来选择驱动表,oracle建议使用leading,他更为灵活
select /*+ order */ t.* from t,t1 where t.id=t1.id;
/*+ use_nl(table_1,table_2) */
在多表关联查询中,指定使用nest loops方式进行多表关联。
select /*+ use_nl(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ use_hash(table_1,table_2) */
在多表关联查询中,指定使用hash join方式进行多表关联。
select /*+ use_hash(t,t1) */ t.* from t,t1 where t.id=t1.id;
在多表关联查询中,指定使用hash join方式进行多表关联,并指定表t为驱动表。
select /*+ use_hash(t,t1) leading(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ use_merge(table_1,table_2) */
在多表关联查询中,指定使用merge join方式进行多表关联。
select /*+ use_merge(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ no_use_nl(table_1,table_2) */
在多表关联查询中,指定不使用nest loops方式进行多表关联。
select /*+ no_use_nl(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ no_use_hash(table_1,table_2) */
在多表关联查询中,指定不使用hash join方式进行多表关联。
select /*+ no_use_hash(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ no_use_merge(table_1,table_2) */
在多表关联查询中,指定不使用merge join方式进行多表关联。
select /*+ no_use_merge(t,t1) */ t.* from t,t1 where t.id=t1.id;
其他常用的hint
/*+ parallel(table_name n) */
在sql中指定执行的并行度,这个值将会覆盖自身的并行度
select /*+ parallel(t 4) */ count(*) from t;
/*+ no_parallel(table_name) */
在sql中指定执行的不使用并行
select /*+ no_parallel(t) */ count(*) from t;
/*+ append */以直接加载的方式将数据加载入库
insert into t /*+ append */ select * from t;
/*+ dynamic_sampling(table_name n) */
设置sql执行时动态采用的级别,这个级别为0~10
select /*+ dynamic_sampling(t 4) */ * from t where id > 1234
/*+ cache(table_name) */
进行全表扫描时将table置于LRU列表的最活跃端,类似于table的cache属性
select /*+ full(employees) cache(employees) */ last_name from employees
附录hint表格
Hints for Optimization Approaches and Goals |
|
ALL_ROWS |
The ALL_ROWS hint explicitly chooses the cost-based approach to |
FIRST_ROWS |
The FIRST_ROWS hint explicitly chooses the cost-based approach to optimize a statement block with a goal |
CHOOSE |
The CHOOSE hint causes the optimizer to choose between the rule-based |
RULE |
The RULE hint explicitly chooses rule-based optimization for a statement |
Hints for Access Paths |
|
FULL |
The FULL hint explicitly chooses a full table scan for the specified table. The syntax of the FULL hint is |
ROWID |
The ROWID hint explicitly chooses a table scan by ROWID for the specified table. The syntax of the ROWID hint is |
CLUSTER |
The CLUSTER hint explicitly chooses a cluster scan to access the specified table. The syntax of the CLUSTER hint is |
HASH |
The HASH hint explicitly chooses a hash scan to access the specified table. The syntax of the HASH hint is |
HASH_AJ |
The HASH_AJ hint transforms a NOT IN subquery into a hash anti-join to |
INDEX |
The INDEX hint explicitly chooses an index scan for the specified table. |
NO_INDEX |
The NO_INDEX hint explicitly disallows a set of indexes for the specified table. |
INDEX_ASC |
The INDEX_ASC hint explicitly chooses an index scan for the specified table. |
INDEX_COMBINE |
If no indexes are given as arguments for the INDEX_COMBINE hint, the optimizer |
INDEX_JOIN |
Explicitly instructs the optimizer to use an index join as an access |
INDEX_DESC |
The INDEX_DESC hint explicitly chooses an index scan for the specified table. If the statement |
INDEX_FFS |
This hint causes a fast full index scan to be performed rather than a full table. |
NO_INDEX_FFS |
Do not use fast full index scan (from Oracle 10g) |
INDEX_SS |
Exclude range scan from query plan (from Oracle 10g) |
INDEX_SS_ASC |
Exclude range scan from query plan (from Oracle 10g) |
INDEX_SS_DESC |
Exclude range scan from query plan (from Oracle 10g) |
NO_INDEX_SS |
The NO_INDEX_SS hint causes the optimizer to exclude a skip scan of the specified indexes on the |
Hints for Query Transformations |
|
NO_QUERY_TRANSFORMATION |
Prevents the optimizer performing query transformations. (from Oracle 10g) |
USE_CONCAT |
The USE_CONCAT hint forces combined OR conditions in the WHERE clause of a |
NO_EXPAND |
The NO_EXPAND hint prevents the optimizer from considering OR-expansion |
REWRITE |
The REWRITE hint forces the optimizer to rewrite a query in terms of |
NOREWRITE / NO_REWRITE |
In Oracle 10g renamed to NO_REWRITE. |
MERGE |
The MERGE hint lets you merge views in a query. |
NO_MERGE |
The NO_MERGE hint causes Oracle not to merge mergeable views. |
FACT |
The FACT hint indicated that the table should be considered as a fact table. |
NO_FACT |
The NO_FACT hint is used in the context of the star transformation to |
STAR_TRANSFORMATION |
The STAR_TRANSFORMATION hint makes the optimizer use the best plan in |
NO_STAR_TRANSFORMATION |
Do not use star transformation (from Oracle 10g) |
UNNEST |
The UNNEST hint specifies subquery unnesting. |
NO_UNNEST |
Use of the NO_UNNEST hint turns off unnesting for specific subquery blocks. |
Hints for Join Orders |
|
LEADING |
Give this hint to indicate the leading table in a join. |
ORDERED |
The ORDERED hint causes Oracle to join tables in the order in which |
Hints for Join Operations |
|
USE_NL |
The USE_NL hint causes Oracle to join each specified table to another row |
NO_USE_NL |
Do not use nested loop (from Oracle 10g) |
USE_NL_WITH_INDEX |
Specifies a nested loops join. (from Oracle 10g) |
USE_MERGE |
The USE_MERGE hint causes Oracle to join each specified table with another row |
NO_USE_MERGE |
Do not use merge (from Oracle 10g) |
USE_HASH |
The USE_HASH hint causes Oracle to join each specified table with another |
NO_USE_HASH |
Do not use hash (from Oracle 10g) |
Hints for Parallel Execution | |
PARALLEL |
The PARALLEL hint allows you to specify the desired number of concurrent |
NOPARALLEL / NO_PARALLEL |
The NOPARALLEL hint allows you to disable parallel scanning of a table, even |
PQ_DISTRIBUTE |
The PQ_DISTRIBUTE hint improves the performance of parallel join |
NO_PARALLEL_INDEX |
The NO_PARALLEL_INDEX hint overrides a PARALLEL attribute setting on an index to avoid a parallel index scan operation. |
Additional Hints | |
APPEND |
When the APPEND hint is used with the INSERT statement, data is appended |
NOAPPEND |
Overrides the append mode. |
CACHE |
The CACHE hint specifies that the blocks retrieved for the table |
NOCACHE |
The NOCACHE hint specifies that the blocks retrieved for this table |
PUSH_PRED |
The PUSH_PRED hint forces pushing of a join predicate into the view. |
NO_PUSH_PRED |
The NO_PUSH_PRED hint prevents pushing of a join predicate into the view. |
PUSH_SUBQ |
The PUSH_SUBQ hint causes nonmerged subqueries to be evaluated at the earliest possible |
NO_PUSH_SUBQ |
The NO_PUSH_SUBQ hint causes non-merged subqueries to be evaluated as the last step in the execution plan. |
QB_NAME |
Specifies a name for a query block. (from Oracle 10g) |
CURSOR_SHARING_EXACT |
Oracle can replace literals in SQL statements with bind variables, if it |
DRIVING_SITE |
The DRIVING_SITE hint forces query execution to be done for the table at a different site than that selected by Oracle |
DYNAMIC_SAMPLING |
The DYNAMIC_SAMPLING hint lets you control dynamic sampling to improve |
SPREAD_MIN_ANALYSIS |
This hint omits some of the compile time optimizations of the rules, |
Hints with unknown status |
|
MERGE_AJ |
The MERGE_AJ hint transforms a NOT IN subquery into a merge anti-join to |
AND_EQUAL |
The AND_EQUAL hint explicitly chooses an execution plan that uses an access |
STAR |
The STAR hint forces the large table to be joined last using a nested loops |
BITMAP |
Usage: BITMAP(table_name index_name) |
HASH_SJ |
Use a Hash Anti-Join to evaluate a NOT IN sub-query. Use this hint in the sub-query, not in the main query. |
NL_SJ |
Use a Nested Loop in a sub-query. (depricated in Oracle 10g) |
NL_AJ |
Use an anti-join in a sub-query. (depricated in Oracle 10g) |
ORDERED_PREDICATES |
(depricated in Oracle 10g) |
EXPAND_GSET_TO_UNION |
(depricated in Oracle 10g) |
参考至:《让Oracle跑得更快》谭怀远著
http://www.oradev.com/hints.jsp
http://hi.baidu.com/lyq168/blog/item/c813452c29d307e48a1399b1.html
http://database.51cto.com/art/200911/163085.htm
http://oracle.chinaitlab.com/induction/398193.html
本文原创,转载请注明出处
如有错误,欢迎指正
邮箱:czmcj@163.com
Oracle中Hint深入理解的更多相关文章
- [转]Oracle中Hint深入理解
原文地址:http://czmmiao.iteye.com/blog/1478465 Hint概述 基于代价的优化器是很聪明的,在绝大多数情况下它会选择正确的优化器,减轻了DBA的负担.但有时它也聪明 ...
- Oracle中Hint深入理解(原创)
http://czmmiao.iteye.com/blog/1478465 Hint概述 基于代价的优化器是很聪明的,在绝大多数情况下它会选择正确的优化器,减轻了DBA的负担.但有时它也聪明反被聪明 ...
- oracle中hint 详解
Hint概述 基于代价的优化器是很聪明的,在绝大多数情况下它会选择正确的优化器,减轻了DBA的负担.但有时它也聪明反被聪明误,选择了很差的执行计划,使某个语句的执行变得奇慢无比. 此时就需要DBA进行 ...
- oracle中的exists理解
select * from EB where exists (select * from BB where Code=EB.Code) 把select 外层表EB看成是循环的,把每一个值eb.code ...
- oracle中null的理解
< EXAMNO STUNO WRITTENEXAM LABEXAM e2014070001 s25301 80 58 e2014070002 s25302 50 e2014070003 s ...
- oracle中 connect by prior 递归算法 -- 理解
oracle中 connect by prior 递归算法 -- 理解 http://blog.163.com/xxciof/blog/static/7978132720095193113752/ ...
- 理解oracle中连接和会话
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp44 理解oracle中连接和会话 1. 概念不同:概念不同: 连接是指物 ...
- Oracle中rownum和rowid的理解
rownum,rowid都叫伪列. 但是,rownum是逻辑上的编号,且其值总是从1开始,每行的rounum不是固定的.而rowid是“物理”编号.若数据库文件没有移动,则每行的 rowid一般是固定 ...
- Oracle中B-TREE索引的深入理解(转载)
索引概述 索引与表一样,也属于段(segment)的一种.里面存放了用户的数据,跟表一样需要占用磁盘空间.只不过,在索引里的数据存放形式与表里的数据存放形式非常的不一样.在理解索引时,可以想象一本书, ...
随机推荐
- vim 翻页命令记录
vim命令: ctrl-f:往前翻一页(forward) ctrl-b:往后翻一页(backward) ctrl-d:往下翻半页(down) ctrl-u:往上翻半页(up)
- Java面试题之final、finally和finalize的区别
final: final是一个修饰符,可以修饰变量.方法和类,如果final修饰变量,意味着变量的值在初始化后不能被改变: 防止编译器把final域重排序到构造函数外:(面试的时候估计答出这个估计会加 ...
- 按 Tab 在多个 InputField 间切换
下面这个链接里的有些unity的东西还没搞懂..改天继续看 http://forum.unity3d.com/threads/tab-between-input-fields.263779/ if(I ...
- 区间求mex的几种方法
Tags : 总结 莫队 线段树 区间取mex的几种方法 题目大意 无修改,求区间 \(mex\) 做法1 莫队+二分+树状数组 树状数组维护维护桶,每次扫完二分答案,用树状数组判断 \(O(n\sq ...
- hdu 1695 容斥原理或莫比乌斯反演
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- c++函数学习-关于c++函数的林林总总
本文是我在学习c++过程中的一些思考和总结,主要是c++中关于函数的林林总总.欢迎大家批评和指正,共同学习. os version: ubuntu 12.04 LTS gcc version: gcc ...
- dpkg --add-architecture i386 && apt-get update && > apt-get install wine32
dpkg --add-architecture i386 && apt-get update &&> apt-get install wine32
- Struts+ibatis-学习总结二
1封装json 在Action中以传统方式输出JSON数据 这一点跟传统的Servlet的处理方式基本上一模一样,代码如下 public void doAction() throws IOExcept ...
- babel转码神器babel-preset-env
简介 现如今不同的浏览器和平台chrome, opera, edge, firefox, safari, ie, ios, android, node, electron 不同的模块 "am ...
- 小程序 之登录 wx.login()
小程序的登录关键在于使用wx.login()方法后,要到取到code值传到后台, 再用小程序平台本帐号生成的appid+addsecret+code去微信接口服务取得用户唯一标识后即可登录[注意:此步 ...