PostgreSQL pg 的SQL优化相关工具和方法

SQL优化通常是较为复杂的工作,需要很多SQL语法知识和优化器相关知识。但是,相关分析诊断工具也非常重要。掌握了这些工具,也非常有助于提升SQL优化器相关技术知识。

SQL优化的主要工具通常是访问计划、统计信息和调试信息。下面是pg相关工具的官方文档。

pg的EXPLAIN命令说明文档:
https://www.postgresql.org/docs/9.3/sql-explain.html

pg的ANALYZE命令说明文档
https://www.postgresql.org/docs/9.3/sql-analyze.html

pg日志打开调试日志,可以看到优化器的诊断信息,官方文档:
https://www.postgresql.org/docs/9.3/runtime-config-logging.html

下面内容简要展示这些工具的使用方法。

查看当前所有连接状态,含正在执行的SQL:

test=# select * from pg_stat_activity;
 datid | datname |  pid  | usesysid | usename  | application_name | client_addr | client_hostname | client_port |        backend_start         |          xact_start   
       |         query_start          |         state_change          | waiting | state  |              query              
-------+---------+-------+----------+----------+------------------+-------------+-----------------+-------------+------------------------------+-----------------------
-------+------------------------------+-------------------------------+---------+--------+---------------------------------
 16384 | test    | 49723 |       10 | sdbadmin | psql             |             |                 |          -1 | 2020-01-08 19:26:38.72099+08 | 2020-01-08 22:28:42.02
633+08 | 2020-01-08 22:28:42.02633+08 | 2020-01-08 22:28:42.026334+08 | f       | active | select * from pg_stat_activity;
(1 row)

只生成访问计划:

test=#  EXPLAIN (ANALYZE FALSE, VERBOSE TRUE, COSTS TRUE, BUFFERS FALSE, TIMING FALSE, FORMAT TEXT) select * from accounts where  account_id='A11111';
                             QUERY PLAN                             
--------------------------------------------------------------------
 Foreign Scan on public.accounts  (cost=0.00..0.06 rows=1 width=18)
   Output: account_id, cust_id, balance
   Filter: (accounts.account_id = 'A11111'::text)
   Foreign Namespace: test_db.accounts
     Filter: ({ "account_id": { "$et": "A11111" } })
(5 rows)

收集统计信息、执行并生成访问计划:

test=# EXPLAIN (ANALYZE TRUE, VERBOSE TRUE, COSTS TRUE, BUFFERS TRUE, TIMING TRUE, FORMAT TEXT) select * from accounts where  account_id='A11111';
                                                  QUERY PLAN                                                  
--------------------------------------------------------------------------------------------------------------
 Foreign Scan on public.accounts  (cost=0.00..0.06 rows=1 width=18) (actual time=7.288..7.290 rows=1 loops=1)
   Output: account_id, cust_id, balance
   Filter: (accounts.account_id = 'A11111'::text)
   Foreign Namespace: test_db.accounts
     Filter: ({ "account_id": { "$et": "A11111" } })
 Total runtime: 8.675 ms
(6 rows)

生成统计信息:

test=# analyze verbose accounts;
INFO:  analyzing "public.accounts"
INFO:  "accounts": collection contains 1 rows; 1 rows in sample
ANALYZE

查看统计信息:

test=# select * from pg_class where relname='accounts';
 relname  | relnamespace | reltype | reloftype | relowner | relam | relfilenode | reltablespace | relpages | reltuples | relallvisible | reltoastrelid | reltoastidxid 
| relhasindex | relisshared | relpersistence | relkind | relnatts | relchecks | relhasoids | relhaspkey | relhasrules | relhastriggers | relhassubclass | relispopulate
d | relfrozenxid | relminmxid | relacl | reloptions 
----------+--------------+---------+-----------+----------+-------+-------------+---------------+----------+-----------+---------------+---------------+---------------
+-------------+-------------+----------------+---------+----------+-----------+------------+------------+-------------+----------------+----------------+--------------
--+--------------+------------+--------+------------
 accounts |         2200 |   49163 |         0 |       10 |     0 |       49161 |             0 |        0 |         1 |             0 |             0 |             0 
| f           | f           | p              | f       |        3 |         0 | f          | f          | f           | f              | f              | t            
  |            0 |          0 |        | 
(1 row)

注: reltuples 是记录数。

查看数值分布:

test=# select * from pg_stats where tablename='accounts';
 schemaname | tablename |  attname   | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_co
mmon_elems | most_common_elem_freqs | elem_count_histogram 
------------+-----------+------------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+--------
-----------+------------------------+----------------------
 public     | accounts  | account_id | f         |         0 |         7 |         -1 |                  |                   |                  |             |        
           |                        | 
 public     | accounts  | cust_id    | f         |         0 |         6 |         -1 |                  |                   |                  |             |        
           |                        | 
 public     | accounts  | balance    | f         |         0 |         5 |         -1 |                  |                   |                  |             |        
           |                        | 
(3 rows)

修改pg配置参数,然后生效,以便于打开调试模式:

test=# SET log_min_messages=debug5;
SET
test=# SET debug_print_parse=on;
SET
test=# SET debug_print_rewritten=on;
SET
test=# SET debug_print_plan=on;
SET
test=# SET debug_pretty_print=on;
SET
test=# SELECT pg_reload_conf();
 pg_reload_conf 
----------------
 t
(1 row)

注释:debug5这个日志级别会造成大量日志记录,分析诊断完成之后,记得将这些值修改回原来值。

debug5模式下,日志记录的示例内容:
下面是执行 explain select * from accounts where account_id=‘A11111’; 时的日志记录:

2020-01-08 23:21:32.990 CST 25843 [local]DEBUG:  StartTransactionCommand
2020-01-08 23:21:32.990 CST 25843 [local]DEBUG:  StartTransaction
2020-01-08 23:21:32.990 CST 25843 [local]DEBUG:  name: unnamed; blockState:       DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children: 
2020-01-08 23:21:32.991 CST 25843 [local]LOG:  parse tree:
2020-01-08 23:21:32.991 CST 25843 [local]DETAIL:     {QUERY 
	   :commandType 5 
	   :querySource 0 
	   :canSetTag true 
	   :utilityStmt ? 
	   :resultRelation 0 
	   :hasAggs false 
	   :hasWindowFuncs false 
	   :hasSubLinks false 
	   :hasDistinctOn false 
	   :hasRecursive false 
	   :hasModifyingCTE false 
	   :hasForUpdate false 
	   :cteList <> 
	   :rtable <> 
	   :jointree <> 
	   :targetList <> 
	   :returningList <> 
	   :groupClause <> 
	   :havingQual <> 
	   :windowClause <> 
	   :distinctClause <> 
	   :sortClause <> 
	   :limitOffset <> 
	   :limitCount <> 
	   :rowMarks <> 
	   :setOperations <> 
	   :constraintDeps <>
	   }
	
2020-01-08 23:21:32.991 CST 25843 [local]STATEMENT:  explain select * from accounts where account_id='A11111';
2020-01-08 23:21:32.991 CST 25843 [local]LOG:  rewritten parse tree:
2020-01-08 23:21:32.991 CST 25843 [local]DETAIL:  (
	   {QUERY 
	   :commandType 5 
	   :querySource 0 
	   :canSetTag true 
	   :utilityStmt ? 
	   :resultRelation 0 
	   :hasAggs false 
	   :hasWindowFuncs false 
	   :hasSubLinks false 
	   :hasDistinctOn false 
	   :hasRecursive false 
	   :hasModifyingCTE false 
	   :hasForUpdate false 
	   :cteList <> 
	   :rtable <> 
	   :jointree <> 
	   :targetList <> 
	   :returningList <> 
	   :groupClause <> 
	   :havingQual <> 
	   :windowClause <> 
	   :distinctClause <> 
	   :sortClause <> 
	   :limitOffset <> 
	   :limitCount <> 
	   :rowMarks <> 
	   :setOperations <> 
	   :constraintDeps <>
	   }
	)
	
2020-01-08 23:21:32.991 CST 25843 [local]STATEMENT:  explain select * from accounts where account_id='A11111';
2020-01-08 23:21:32.991 CST 25843 [local]DEBUG:  ProcessUtility
2020-01-08 23:21:32.992 CST 25843 [local]DEBUG:  hostName=c1:11810,c2:11810,c3:11810,service=0
2020-01-08 23:21:32.992 CST 25843 [local]DEBUG:  foreign table:49161, handle found:0
2020-01-08 23:21:32.992 CST 25843 [local]DEBUG:  hostName=c1:11810,c2:11810,c3:11810,service=0
2020-01-08 23:21:32.993 CST 25843 [local]DEBUG:  hostName=c1:11810,c2:11810,c3:11810,service=0
2020-01-08 23:21:32.993 CST 25843 [local]DEBUG:  connecting :list=c1:11810:c2:11810:c3:11810:::,num=3
2020-01-08 23:21:33.006 CST 25843 [local]DEBUG:  bson value={ "PreferedInstance": "a", "Source": "pg-25843" },label[display session attr]
2020-01-08 23:21:33.006 CST 25843 [local]DEBUG:  setting session attr
2020-01-08 23:21:33.040 CST 25843 [local]DEBUG:  var info:foreign_table_id=49161, varattno=1, valevelsup=0
2020-01-08 23:21:33.040 CST 25843 [local]DEBUG:  isSortCanPushDown:empty pathkeys
2020-01-08 23:21:33.040 CST 25843 [local]DEBUG:  foreign table:49161, handle found:1
2020-01-08 23:21:33.040 CST 25843 [local]DEBUG:  get index from db
2020-01-08 23:21:33.048 CST 25843 [local]DEBUG:  SdbGetForeignPaths:foreignPath={FOREIGNPATH :pathtype 120 :parent_relids (b 1) :required_outer (b) :rows 1 :startup_cost 0.00 :total_cost 0.06 :pathkeys <> :fdw_private <>}
2020-01-08 23:21:33.048 CST 25843 [local]DEBUG:  foreign table:49161, handle found:1
2020-01-08 23:21:33.048 CST 25843 [local]DEBUG:  SdbGetForeignPlan:bestPath={FOREIGNPATH :pathtype 120 :parent_relids (b 1) :required_outer (b) :rows 1 :startup_cost 0.00 :total_cost 0.06 :pathkeys <> :fdw_private <>}
2020-01-08 23:21:33.049 CST 25843 [local]DEBUG:  var info:foreign_table_id=49161, varattno=1, valevelsup=0
2020-01-08 23:21:33.049 CST 25843 [local]DEBUG:  bson value={ "account_id": { "$et": "A11111" } },label[SdbGetForeignPlan query]
2020-01-08 23:21:33.049 CST 25843 [local]DEBUG:  reset parse's limit and offset
2020-01-08 23:21:33.049 CST 25843 [local]DEBUG:  SdbAllocRecord:usedCount=1,index=0
2020-01-08 23:21:33.051 CST 25843 [local]LOG:  plan:
2020-01-08 23:21:33.051 CST 25843 [local]DETAIL:     {PLANNEDSTMT 
	   :commandType 1 
	   :queryId 0 
	   :hasReturning false 
	   :hasModifyingCTE false 
	   :canSetTag true 
	   :transientPlan false 
	   :planTree 
	      {FOREIGNSCAN 
	      :startup_cost 0.00 
	      :total_cost 0.06 
	      :plan_rows 1 
	      :plan_width 18 
	      :targetlist (
	         {TARGETENTRY 
	         :expr 
	            {VAR 
	            :varno 1 
	            :varattno 1 
	            :vartype 25 
	            :vartypmod -1 
	            :varcollid 100 
	            :varlevelsup 0 
	            :varnoold 1 
	            :varoattno 1 
	            :location 15
	            }
	         :resno 1 
	         :resname account_id 
	         :ressortgroupref 0 
	         :resorigtbl 49161 
	         :resorigcol 1 
	         :resjunk false
	         }
	         {TARGETENTRY 
	         :expr 
	            {VAR 
	            :varno 1 
	            :varattno 2 
	            :vartype 25 
	            :vartypmod -1 
	            :varcollid 100 
	            :varlevelsup 0 
	            :varnoold 1 
	            :varoattno 2 
	            :location 15
	            }
	         :resno 2 
	         :resname cust_id 
	         :ressortgroupref 0 
	         :resorigtbl 49161 
	         :resorigcol 2 
	         :resjunk false
	         }
	         {TARGETENTRY 
	         :expr 
	            {VAR 
	            :varno 1 
	            :varattno 3 
	            :vartype 1700 
	            :vartypmod 1310730 
	            :varcollid 0 
	            :varlevelsup 0 
	            :varnoold 1 
	            :varoattno 3 
	            :location 15
	            }
	         :resno 3 
	         :resname balance 
	         :ressortgroupref 0 
	         :resorigtbl 49161 
	         :resorigcol 3 
	         :resjunk false
	         }
	      )
	      :qual (
	         {OPEXPR 
	         :opno 98 
	         :opfuncid 67 
	         :opresulttype 16 
	         :opretset false 
	         :opcollid 0 
	         :inputcollid 100 
	         :args (
	            {VAR 
	            :varno 1 
	            :varattno 1 
	            :vartype 25 
	            :vartypmod -1 
	            :varcollid 100 
	            :varlevelsup 0 
	            :varnoold 1 
	            :varoattno 1 
	            :location 37
	            }
	            {CONST 
	            :consttype 25 
	            :consttypmod -1 
	            :constcollid 100 
	            :constlen -1 
	            :constbyval false 
	            :constisnull false 
	            :location 48 
	            :constvalue 10 [ 40 0 0 0 65 49 49 49 49 49 ]
	            }
	         )
	         :location 47
	         }
	      )
	      :lefttree <> 
	      :righttree <> 
	      :initPlan <> 
	      :extParam (b)
	      :allParam (b)
	      :scanrelid 1 
	      :fdw_exprs <> 
	      :fdw_private ((
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 3 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 12 [ 48 0 0 0 99 49 58 49 49 56 49 48 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 12 [ 48 0 0 0 99 50 58 49 49 56 49 48 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 12 [ 48 0 0 0 99 51 58 49 49 56 49 48 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 16 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 16 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull true 
	         :location -1 
	         :constvalue <>
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 0 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull true 
	         :location -1 
	         :constvalue <>
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 5 [ 20 0 0 0 97 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 16 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ -1 -1 -1 -1 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 7 [ 28 0 0 0 79 70 70 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 11 [ 44 0 0 0 116 101 115 116 95 100 98 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 12 [ 48 0 0 0 97 99 99 111 117 110 116 115 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 12 [ 48 0 0 0 97 99 99 111 117 110 116 115 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 3 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 14 [ 56 0 0 0 97 99 99 111 117 110 116 95 105 100 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 1 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 26 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 25 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ -1 -1 -1 -1 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 11 [ 44 0 0 0 99 117 115 116 95 105 100 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 2 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 26 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 25 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ -1 -1 -1 -1 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 11 [ 44 0 0 0 98 97 108 97 110 99 101 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 3 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 26 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ -92 6 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 10 0 20 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 2275 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 39 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 39 [ 38 0 0 0 3 97 99 99 111 117 110 116 95 105 100 0 21 
	         0 0 0 2 36 101 116 0 7 0 0 0 65 49 49 49 49 49 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 2275 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 6 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 6 [ 5 0 0 0 0 127 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 8 
	         :constbyval false 
	         :constisnull true 
	         :location -1 
	         :constvalue <>
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 8 
	         :constbyval false 
	         :constisnull true 
	         :location -1 
	         :constvalue <>
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 1 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 1 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 8 
	         :constbyval false 
	         :constisnull true 
	         :location -1 
	         :constvalue <>
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 1 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 26 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 9 -64 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 1 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 2 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 7 [ 28 0 0 0 95 105 100 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 14 [ 56 0 0 0 97 99 99 111 117 110 116 95 105 100 ]
	         }
	      )
	      (
	         {VAR 
	         :varno 1 
	         :varattno 1 
	         :vartype 25 
	         :vartypmod -1 
	         :varcollid 100 
	         :varlevelsup 0 
	         :varnoold 1 
	         :varoattno 1 
	         :location 15
	         }
	         {VAR 
	         :varno 1 
	         :varattno 2 
	         :vartype 25 
	         :vartypmod -1 
	         :varcollid 100 
	         :varlevelsup 0 
	         :varnoold 1 
	         :varoattno 2 
	         :location 15
	         }
	         {VAR 
	         :varno 1 
	         :varattno 3 
	         :vartype 1700 
	         :vartypmod 1310730 
	         :varcollid 0 
	         :varlevelsup 0 
	         :varnoold 1 
	         :varoattno 3 
	         :location 15
	         }
	      ))
	      :fsSystemCol false
	      }
	   :rtable (
	      {RTE 
	      :alias <> 
	      :eref 
	         {ALIAS 
	         :aliasname accounts 
	         :colnames ("account_id" "cust_id" "balance")
	         }
	      :rtekind 0 
	      :relid 49161 
	      :relkind f 
	      :lateral false 
	      :inh false 
	      :inFromCl true 
	      :requiredPerms 2 
	      :checkAsUser 0 
	      :selectedCols (b 9 10 11)
	      :modifiedCols (b)
	      }
	   )
	   :resultRelations <> 
	   :utilityStmt <> 
	   :subplans <> 
	   :rewindPlanIDs (b)
	   :rowMarks <> 
	   :relationOids (o 49161)
	   :invalItems <> 
	   :nParamExec 0
	   }
	
2020-01-08 23:21:33.051 CST 25843 [local]STATEMENT:  explain select * from accounts where account_id='A11111';
2020-01-08 23:21:33.051 CST 25843 [local]DEBUG:  hostName=c1:11810,c2:11810,c3:11810,service=0
2020-01-08 23:21:33.051 CST 25843 [local]DEBUG:  CommitTransactionCommand
2020-01-08 23:21:33.051 CST 25843 [local]DEBUG:  CommitTransaction
2020-01-08 23:21:33.051 CST 25843 [local]DEBUG:  name: unnamed; blockState:       STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children: 

下面是执行 select * from accounts where account_id=‘A11111’; 的日志记录:

2020-01-08 23:23:50.994 CST 25843 [local]DEBUG:  StartTransactionCommand
2020-01-08 23:23:50.994 CST 25843 [local]DEBUG:  StartTransaction
2020-01-08 23:23:50.994 CST 25843 [local]DEBUG:  name: unnamed; blockState:       DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children: 
2020-01-08 23:23:50.995 CST 25843 [local]LOG:  parse tree:
2020-01-08 23:23:50.995 CST 25843 [local]DETAIL:     {QUERY 
	   :commandType 1 
	   :querySource 0 
	   :canSetTag true 
	   :utilityStmt <> 
	   :resultRelation 0 
	   :hasAggs false 
	   :hasWindowFuncs false 
	   :hasSubLinks false 
	   :hasDistinctOn false 
	   :hasRecursive false 
	   :hasModifyingCTE false 
	   :hasForUpdate false 
	   :cteList <> 
	   :rtable (
	      {RTE 
	      :alias <> 
	      :eref 
	         {ALIAS 
	         :aliasname accounts 
	         :colnames ("account_id" "cust_id" "balance")
	         }
	      :rtekind 0 
	      :relid 49161 
	      :relkind f 
	      :lateral false 
	      :inh true 
	      :inFromCl true 
	      :requiredPerms 2 
	      :checkAsUser 0 
	      :selectedCols (b 9 10 11)
	      :modifiedCols (b)
	      }
	   )
	   :jointree 
	      {FROMEXPR 
	      :fromlist (
	         {RANGETBLREF 
	         :rtindex 1
	         }
	      )
	      :quals 
	         {OPEXPR 
	         :opno 98 
	         :opfuncid 67 
	         :opresulttype 16 
	         :opretset false 
	         :opcollid 0 
	         :inputcollid 100 
	         :args (
	            {VAR 
	            :varno 1 
	            :varattno 1 
	            :vartype 25 
	            :vartypmod -1 
	            :varcollid 100 
	            :varlevelsup 0 
	            :varnoold 1 
	            :varoattno 1 
	            :location 29
	            }
	            {CONST 
	            :consttype 25 
	            :consttypmod -1 
	            :constcollid 100 
	            :constlen -1 
	            :constbyval false 
	            :constisnull false 
	            :location 40 
	            :constvalue 10 [ 40 0 0 0 65 49 49 49 49 49 ]
	            }
	         )
	         :location 39
	         }
	      }
	   :targetList (
	      {TARGETENTRY 
	      :expr 
	         {VAR 
	         :varno 1 
	         :varattno 1 
	         :vartype 25 
	         :vartypmod -1 
	         :varcollid 100 
	         :varlevelsup 0 
	         :varnoold 1 
	         :varoattno 1 
	         :location 7
	         }
	      :resno 1 
	      :resname account_id 
	      :ressortgroupref 0 
	      :resorigtbl 49161 
	      :resorigcol 1 
	      :resjunk false
	      }
	      {TARGETENTRY 
	      :expr 
	         {VAR 
	         :varno 1 
	         :varattno 2 
	         :vartype 25 
	         :vartypmod -1 
	         :varcollid 100 
	         :varlevelsup 0 
	         :varnoold 1 
	         :varoattno 2 
	         :location 7
	         }
	      :resno 2 
	      :resname cust_id 
	      :ressortgroupref 0 
	      :resorigtbl 49161 
	      :resorigcol 2 
	      :resjunk false
	      }
	      {TARGETENTRY 
	      :expr 
	         {VAR 
	         :varno 1 
	         :varattno 3 
	         :vartype 1700 
	         :vartypmod 1310730 
	         :varcollid 0 
	         :varlevelsup 0 
	         :varnoold 1 
	         :varoattno 3 
	         :location 7
	         }
	      :resno 3 
	      :resname balance 
	      :ressortgroupref 0 
	      :resorigtbl 49161 
	      :resorigcol 3 
	      :resjunk false
	      }
	   )
	   :returningList <> 
	   :groupClause <> 
	   :havingQual <> 
	   :windowClause <> 
	   :distinctClause <> 
	   :sortClause <> 
	   :limitOffset <> 
	   :limitCount <> 
	   :rowMarks <> 
	   :setOperations <> 
	   :constraintDeps <>
	   }
	
2020-01-08 23:23:50.995 CST 25843 [local]STATEMENT:  select * from accounts where account_id='A11111';
2020-01-08 23:23:50.995 CST 25843 [local]LOG:  rewritten parse tree:
2020-01-08 23:23:50.995 CST 25843 [local]DETAIL:  (
	   {QUERY 
	   :commandType 1 
	   :querySource 0 
	   :canSetTag true 
	   :utilityStmt <> 
	   :resultRelation 0 
	   :hasAggs false 
	   :hasWindowFuncs false 
	   :hasSubLinks false 
	   :hasDistinctOn false 
	   :hasRecursive false 
	   :hasModifyingCTE false 
	   :hasForUpdate false 
	   :cteList <> 
	   :rtable (
	      {RTE 
	      :alias <> 
	      :eref 
	         {ALIAS 
	         :aliasname accounts 
	         :colnames ("account_id" "cust_id" "balance")
	         }
	      :rtekind 0 
	      :relid 49161 
	      :relkind f 
	      :lateral false 
	      :inh true 
	      :inFromCl true 
	      :requiredPerms 2 
	      :checkAsUser 0 
	      :selectedCols (b 9 10 11)
	      :modifiedCols (b)
	      }
	   )
	   :jointree 
	      {FROMEXPR 
	      :fromlist (
	         {RANGETBLREF 
	         :rtindex 1
	         }
	      )
	      :quals 
	         {OPEXPR 
	         :opno 98 
	         :opfuncid 67 
	         :opresulttype 16 
	         :opretset false 
	         :opcollid 0 
	         :inputcollid 100 
	         :args (
	            {VAR 
	            :varno 1 
	            :varattno 1 
	            :vartype 25 
	            :vartypmod -1 
	            :varcollid 100 
	            :varlevelsup 0 
	            :varnoold 1 
	            :varoattno 1 
	            :location 29
	            }
	            {CONST 
	            :consttype 25 
	            :consttypmod -1 
	            :constcollid 100 
	            :constlen -1 
	            :constbyval false 
	            :constisnull false 
	            :location 40 
	            :constvalue 10 [ 40 0 0 0 65 49 49 49 49 49 ]
	            }
	         )
	         :location 39
	         }
	      }
	   :targetList (
	      {TARGETENTRY 
	      :expr 
	         {VAR 
	         :varno 1 
	         :varattno 1 
	         :vartype 25 
	         :vartypmod -1 
	         :varcollid 100 
	         :varlevelsup 0 
	         :varnoold 1 
	         :varoattno 1 
	         :location 7
	         }
	      :resno 1 
	      :resname account_id 
	      :ressortgroupref 0 
	      :resorigtbl 49161 
	      :resorigcol 1 
	      :resjunk false
	      }
	      {TARGETENTRY 
	      :expr 
	         {VAR 
	         :varno 1 
	         :varattno 2 
	         :vartype 25 
	         :vartypmod -1 
	         :varcollid 100 
	         :varlevelsup 0 
	         :varnoold 1 
	         :varoattno 2 
	         :location 7
	         }
	      :resno 2 
	      :resname cust_id 
	      :ressortgroupref 0 
	      :resorigtbl 49161 
	      :resorigcol 2 
	      :resjunk false
	      }
	      {TARGETENTRY 
	      :expr 
	         {VAR 
	         :varno 1 
	         :varattno 3 
	         :vartype 1700 
	         :vartypmod 1310730 
	         :varcollid 0 
	         :varlevelsup 0 
	         :varnoold 1 
	         :varoattno 3 
	         :location 7
	         }
	      :resno 3 
	      :resname balance 
	      :ressortgroupref 0 
	      :resorigtbl 49161 
	      :resorigcol 3 
	      :resjunk false
	      }
	   )
	   :returningList <> 
	   :groupClause <> 
	   :havingQual <> 
	   :windowClause <> 
	   :distinctClause <> 
	   :sortClause <> 
	   :limitOffset <> 
	   :limitCount <> 
	   :rowMarks <> 
	   :setOperations <> 
	   :constraintDeps <>
	   }
	)
	
2020-01-08 23:23:50.995 CST 25843 [local]STATEMENT:  select * from accounts where account_id='A11111';
2020-01-08 23:23:50.995 CST 25843 [local]DEBUG:  hostName=c1:11810,c2:11810,c3:11810,service=0
2020-01-08 23:23:50.995 CST 25843 [local]DEBUG:  foreign table:49161, handle found:1
2020-01-08 23:23:50.995 CST 25843 [local]DEBUG:  var info:foreign_table_id=49161, varattno=1, valevelsup=0
2020-01-08 23:23:50.995 CST 25843 [local]DEBUG:  isSortCanPushDown:empty pathkeys
2020-01-08 23:23:50.995 CST 25843 [local]DEBUG:  foreign table:49161, handle found:1
2020-01-08 23:23:50.995 CST 25843 [local]DEBUG:  get index from cache
2020-01-08 23:23:50.995 CST 25843 [local]DEBUG:  i=0,keynum=1,key[0]=account_id
2020-01-08 23:23:50.995 CST 25843 [local]DEBUG:  SdbGetForeignPaths:foreignPath={FOREIGNPATH :pathtype 120 :parent_relids (b 1) :required_outer (b) :rows 1 :startup_cost 0.00 :total_cost 0.06 :pathkeys <> :fdw_private <>}
2020-01-08 23:23:50.995 CST 25843 [local]DEBUG:  foreign table:49161, handle found:1
2020-01-08 23:23:50.995 CST 25843 [local]DEBUG:  SdbGetForeignPlan:bestPath={FOREIGNPATH :pathtype 120 :parent_relids (b 1) :required_outer (b) :rows 1 :startup_cost 0.00 :total_cost 0.06 :pathkeys <> :fdw_private <>}
2020-01-08 23:23:50.995 CST 25843 [local]DEBUG:  var info:foreign_table_id=49161, varattno=1, valevelsup=0
2020-01-08 23:23:50.995 CST 25843 [local]DEBUG:  bson value={ "account_id": { "$et": "A11111" } },label[SdbGetForeignPlan query]
2020-01-08 23:23:50.995 CST 25843 [local]DEBUG:  reset parse's limit and offset
2020-01-08 23:23:50.995 CST 25843 [local]DEBUG:  SdbAllocRecord:usedCount=1,index=0
2020-01-08 23:23:50.996 CST 25843 [local]LOG:  plan:
2020-01-08 23:23:50.997 CST 25843 [local]DETAIL:     {PLANNEDSTMT 
	   :commandType 1 
	   :queryId 0 
	   :hasReturning false 
	   :hasModifyingCTE false 
	   :canSetTag true 
	   :transientPlan false 
	   :planTree 
	      {FOREIGNSCAN 
	      :startup_cost 0.00 
	      :total_cost 0.06 
	      :plan_rows 1 
	      :plan_width 18 
	      :targetlist (
	         {TARGETENTRY 
	         :expr 
	            {VAR 
	            :varno 1 
	            :varattno 1 
	            :vartype 25 
	            :vartypmod -1 
	            :varcollid 100 
	            :varlevelsup 0 
	            :varnoold 1 
	            :varoattno 1 
	            :location 7
	            }
	         :resno 1 
	         :resname account_id 
	         :ressortgroupref 0 
	         :resorigtbl 49161 
	         :resorigcol 1 
	         :resjunk false
	         }
	         {TARGETENTRY 
	         :expr 
	            {VAR 
	            :varno 1 
	            :varattno 2 
	            :vartype 25 
	            :vartypmod -1 
	            :varcollid 100 
	            :varlevelsup 0 
	            :varnoold 1 
	            :varoattno 2 
	            :location 7
	            }
	         :resno 2 
	         :resname cust_id 
	         :ressortgroupref 0 
	         :resorigtbl 49161 
	         :resorigcol 2 
	         :resjunk false
	         }
	         {TARGETENTRY 
	         :expr 
	            {VAR 
	            :varno 1 
	            :varattno 3 
	            :vartype 1700 
	            :vartypmod 1310730 
	            :varcollid 0 
	            :varlevelsup 0 
	            :varnoold 1 
	            :varoattno 3 
	            :location 7
	            }
	         :resno 3 
	         :resname balance 
	         :ressortgroupref 0 
	         :resorigtbl 49161 
	         :resorigcol 3 
	         :resjunk false
	         }
	      )
	      :qual (
	         {OPEXPR 
	         :opno 98 
	         :opfuncid 67 
	         :opresulttype 16 
	         :opretset false 
	         :opcollid 0 
	         :inputcollid 100 
	         :args (
	            {VAR 
	            :varno 1 
	            :varattno 1 
	            :vartype 25 
	            :vartypmod -1 
	            :varcollid 100 
	            :varlevelsup 0 
	            :varnoold 1 
	            :varoattno 1 
	            :location 29
	            }
	            {CONST 
	            :consttype 25 
	            :consttypmod -1 
	            :constcollid 100 
	            :constlen -1 
	            :constbyval false 
	            :constisnull false 
	            :location 40 
	            :constvalue 10 [ 40 0 0 0 65 49 49 49 49 49 ]
	            }
	         )
	         :location 39
	         }
	      )
	      :lefttree <> 
	      :righttree <> 
	      :initPlan <> 
	      :extParam (b)
	      :allParam (b)
	      :scanrelid 1 
	      :fdw_exprs <> 
	      :fdw_private ((
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 3 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 12 [ 48 0 0 0 99 49 58 49 49 56 49 48 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 12 [ 48 0 0 0 99 50 58 49 49 56 49 48 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 12 [ 48 0 0 0 99 51 58 49 49 56 49 48 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 16 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 16 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull true 
	         :location -1 
	         :constvalue <>
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 0 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull true 
	         :location -1 
	         :constvalue <>
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 5 [ 20 0 0 0 97 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 16 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ -1 -1 -1 -1 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 7 [ 28 0 0 0 79 70 70 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 11 [ 44 0 0 0 116 101 115 116 95 100 98 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 12 [ 48 0 0 0 97 99 99 111 117 110 116 115 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 12 [ 48 0 0 0 97 99 99 111 117 110 116 115 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 3 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 14 [ 56 0 0 0 97 99 99 111 117 110 116 95 105 100 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 1 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 26 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 25 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ -1 -1 -1 -1 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 11 [ 44 0 0 0 99 117 115 116 95 105 100 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 2 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 26 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 25 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ -1 -1 -1 -1 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 11 [ 44 0 0 0 98 97 108 97 110 99 101 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 3 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 26 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ -92 6 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 10 0 20 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 2275 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 39 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 39 [ 38 0 0 0 3 97 99 99 111 117 110 116 95 105 100 0 21 
	         0 0 0 2 36 101 116 0 7 0 0 0 65 49 49 49 49 49 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 2275 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 6 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 6 [ 5 0 0 0 0 127 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 8 
	         :constbyval false 
	         :constisnull true 
	         :location -1 
	         :constvalue <>
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 8 
	         :constbyval false 
	         :constisnull true 
	         :location -1 
	         :constvalue <>
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 1 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 1 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 8 
	         :constbyval false 
	         :constisnull true 
	         :location -1 
	         :constvalue <>
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 1 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 26 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 9 -64 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 1 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 23 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen 4 
	         :constbyval true 
	         :constisnull false 
	         :location -1 
	         :constvalue 4 [ 2 0 0 0 0 0 0 0 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 7 [ 28 0 0 0 95 105 100 ]
	         }
	         {CONST 
	         :consttype 25 
	         :consttypmod -1 
	         :constcollid 0 
	         :constlen -1 
	         :constbyval false 
	         :constisnull false 
	         :location -1 
	         :constvalue 14 [ 56 0 0 0 97 99 99 111 117 110 116 95 105 100 ]
	         }
	      )
	      (
	         {VAR 
	         :varno 1 
	         :varattno 1 
	         :vartype 25 
	         :vartypmod -1 
	         :varcollid 100 
	         :varlevelsup 0 
	         :varnoold 1 
	         :varoattno 1 
	         :location 7
	         }
	         {VAR 
	         :varno 1 
	         :varattno 2 
	         :vartype 25 
	         :vartypmod -1 
	         :varcollid 100 
	         :varlevelsup 0 
	         :varnoold 1 
	         :varoattno 2 
	         :location 7
	         }
	         {VAR 
	         :varno 1 
	         :varattno 3 
	         :vartype 1700 
	         :vartypmod 1310730 
	         :varcollid 0 
	         :varlevelsup 0 
	         :varnoold 1 
	         :varoattno 3 
	         :location 7
	         }
	      ))
	      :fsSystemCol false
	      }
	   :rtable (
	      {RTE 
	      :alias <> 
	      :eref 
	         {ALIAS 
	         :aliasname accounts 
	         :colnames ("account_id" "cust_id" "balance")
	         }
	      :rtekind 0 
	      :relid 49161 
	      :relkind f 
	      :lateral false 
	      :inh false 
	      :inFromCl true 
	      :requiredPerms 2 
	      :checkAsUser 0 
	      :selectedCols (b 9 10 11)
	      :modifiedCols (b)
	      }
	   )
	   :resultRelations <> 
	   :utilityStmt <> 
	   :subplans <> 
	   :rewindPlanIDs (b)
	   :rowMarks <> 
	   :relationOids (o 49161)
	   :invalItems <> 
	   :nParamExec 0
	   }
	
2020-01-08 23:23:50.997 CST 25843 [local]STATEMENT:  select * from accounts where account_id='A11111';
2020-01-08 23:23:50.997 CST 25843 [local]DEBUG:  foreign table:49161, handle found:1
2020-01-08 23:23:51.012 CST 25843 [local]DEBUG:  CommitTransactionCommand
2020-01-08 23:23:51.013 CST 25843 [local]DEBUG:  CommitTransaction
2020-01-08 23:23:51.013 CST 25843 [local]DEBUG:  name: unnamed; blockState:       STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children: 
2020-01-08 23:23:52.244 CST 25149 DEBUG:  StartTransaction
2020-01-08 23:23:52.244 CST 25149 DEBUG:  name: unnamed; blockState:       DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children: 
2020-01-08 23:23:52.244 CST 25149 DEBUG:  CommitTransaction
2020-01-08 23:23:52.244 CST 25149 DEBUG:  name: unnamed; blockState:       STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children: 
2020-01-08 23:23:52.244 CST 25150 DEBUG:  received inquiry for 0
2020-01-08 23:23:52.244 CST 25150 DEBUG:  writing statsfile 'pg_stat_tmp/global.stat'
2020-01-08 23:23:52.244 CST 25150 DEBUG:  writing statsfile 'pg_stat_tmp/db_0.stat'
2020-01-08 23:23:52.255 CST 29807 DEBUG:  InitPostgres
2020-01-08 23:23:52.255 CST 29807 DEBUG:  my backend ID is 3
2020-01-08 23:23:52.255 CST 29807 DEBUG:  StartTransaction
2020-01-08 23:23:52.255 CST 29807 DEBUG:  name: unnamed; blockState:       DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children: 
2020-01-08 23:23:52.256 CST 29807 DEBUG:  CommitTransaction
2020-01-08 23:23:52.256 CST 29807 DEBUG:  name: unnamed; blockState:       STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children: 
2020-01-08 23:23:52.256 CST 29807 DEBUG:  autovacuum: processing database "postgres"
2020-01-08 23:23:52.256 CST 25150 DEBUG:  received inquiry for 12949
2020-01-08 23:23:52.256 CST 25150 DEBUG:  writing statsfile 'pg_stat_tmp/global.stat'
2020-01-08 23:23:52.256 CST 25150 DEBUG:  writing statsfile 'pg_stat_tmp/db_12949.stat'
2020-01-08 23:23:52.268 CST 29807 DEBUG:  StartTransaction
2020-01-08 23:23:52.268 CST 29807 DEBUG:  name: unnamed; blockState:       DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children: 
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_statistic: vac: 0 (threshold 128), anl: 0 (threshold 89)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_type: vac: 0 (threshold 117), anl: 0 (threshold 83)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_authid: vac: 0 (threshold 50), anl: 0 (threshold 50)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_attribute: vac: 0 (threshold 505), anl: 0 (threshold 277)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_proc: vac: 0 (threshold 556), anl: 0 (threshold 303)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_class: vac: 0 (threshold 108), anl: 0 (threshold 79)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_index: vac: 0 (threshold 72), anl: 0 (threshold 61)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_opclass: vac: 0 (threshold 74), anl: 0 (threshold 62)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_am: vac: 0 (threshold 51), anl: 0 (threshold 50)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_amop: vac: 0 (threshold 131), anl: 0 (threshold 90)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_amproc: vac: 0 (threshold 108), anl: 0 (threshold 79)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_database: vac: 0 (threshold 50), anl: 0 (threshold 50)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_cast: vac: 0 (threshold 89), anl: 0 (threshold 70)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_namespace: vac: 0 (threshold 51), anl: 0 (threshold 51)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  pg_tablespace: vac: 0 (threshold 50), anl: 0 (threshold 50)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  CommitTransaction
2020-01-08 23:23:52.268 CST 29807 DEBUG:  name: unnamed; blockState:       STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children: 
2020-01-08 23:23:52.268 CST 29807 DEBUG:  shmem_exit(0): 8 callbacks to make
2020-01-08 23:23:52.268 CST 29807 DEBUG:  proc_exit(0): 2 callbacks to make
2020-01-08 23:23:52.268 CST 29807 DEBUG:  exit(0)
2020-01-08 23:23:52.268 CST 29807 DEBUG:  shmem_exit(-1): 0 callbacks to make
2020-01-08 23:23:52.268 CST 29807 DEBUG:  proc_exit(-1): 0 callbacks to make
2020-01-08 23:23:52.269 CST 25124 DEBUG:  reaping dead processes
2020-01-08 23:23:52.269 CST 25124 DEBUG:  server process (PID 29807) exited with exit code 0

你可能感兴趣的:(PostgreSQL pg 的SQL优化相关工具和方法)