Caused by: Vertica error - too complex to analyze

2018.11.30

前言

某工程進行Vertica表間數據拼接,大致SQL語句如下:

insert into tableForInsert as select * from tableA union all select * from tableB ...

union all1的表非常多,導致SQL語句過長,報錯如下:

java.sql.SQLNonTransientException: [Vertica][VJDBC](4963) ERROR: The query contains a SET operation tree that is too complex to analyze

追根溯源

從Vertica的官方文檔2得知,Vertica對於SQL語句有兩條限制:
Vertica Limits to SQL Expressions

  1. The first limit is based on the stack available to the expression. Vertica requires at least 100kb of free stack:第一條是關於SQL語句的大小,要求小於棧大小。這取決於Vertica的配置;
  2. The second limit is the number of recursions possible in an analytic expression. The limit is 2000…cannot be increased:第二條是語句可能的遞歸次數不得超過2000,而且2000是上限,不可增加。

並且根據Vertica官方某博客3可推斷,union all是一條遞歸語句:

Other implementations include ANSI SQL’s recursive SQL syntax using WITH and UNION ALL, special graph based algorithms and enumerated path technique

恍然大悟

綜上,該語句報錯的原因就是SQL語句的union all太多而導致超過2000的上限。最佳解決方案是修改SQL語句,棄用union all進行拼接,根本上避免了會超過上限的可能性;次之的方法,可以考慮將SQL語句縮短。


  1. Vertica Union Clause ↩︎

  2. Vertica Limits to SQL Expressions ↩︎

  3. Can Vertica Climb a Tree? ↩︎

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章