hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [07/17] incubator-hawq git commit: HAWQ-1122. Fix ORCA - gpdb exception handling. This closes #793
Date Fri, 28 Oct 2016 03:53:10 GMT
HAWQ-1122. Fix ORCA - gpdb exception handling. This closes #793

Any GPDB exception happens in while ORCA generating plan will abort
query.

This is cherry-picked from greenplum-db/gpdb@045d437cc1240b0d804ce4a37b5b165ec216afd7

Signed-off-by: Foyzur Rahman <frahman@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/f6b76472
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/f6b76472
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/f6b76472

Branch: refs/heads/master
Commit: f6b76472c9c3112cf83058c78d05cf1a59d8d498
Parents: dc14ecb
Author: Karthikeyan Jambu Rajaraman <karthi.jrk@gmail.com>
Authored: Tue Apr 26 08:21:50 2016 -0700
Committer: rlei <rlei@pivotal.io>
Committed: Fri Oct 28 11:52:20 2016 +0800

----------------------------------------------------------------------
 src/backend/gpopt/CGPOptimizer.cpp              |   16 +-
 src/backend/gpopt/gpdbwrappers.cpp              |    7 +-
 src/backend/gpopt/utils/COptTasks.cpp           |   13 +-
 src/test/regress/expected/abstime_optimizer.out |  137 +
 src/test/regress/expected/errors.out            |    4 +
 src/test/regress/expected/gp_optimizer.out      |   35 +
 src/test/regress/expected/horology.out          |    5 +-
 .../regress/expected/horology_optimizer.out     | 3104 ++++++++++++++++++
 .../regress/expected/namespace_optimizer.out    |  142 +
 .../regress/expected/privileges_optimizer.out   |  733 +++++
 src/test/regress/expected/role_optimizer.out    |  107 +
 src/test/regress/sql/errors.sql                 |    5 +-
 src/test/regress/sql/gp_optimizer.sql           |   25 +
 src/test/regress/sql/horology.sql               |    6 +-
 14 files changed, 4323 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f6b76472/src/backend/gpopt/CGPOptimizer.cpp
----------------------------------------------------------------------
diff --git a/src/backend/gpopt/CGPOptimizer.cpp b/src/backend/gpopt/CGPOptimizer.cpp
index db3cab8..4ade344 100644
--- a/src/backend/gpopt/CGPOptimizer.cpp
+++ b/src/backend/gpopt/CGPOptimizer.cpp
@@ -37,6 +37,8 @@
 #include "gpopt/init.h"
 #include "gpos/_api.h"
 
+#include "naucrates/exception.h"
+
 //---------------------------------------------------------------------------
 //	@function:
 //		CGPOptimizer::TouchLibraryInitializers
@@ -69,7 +71,19 @@ CGPOptimizer::PplstmtOptimize
 	bool *pfUnexpectedFailure // output : set to true if optimizer unexpectedly failed to produce
plan
 	)
 {
-	return COptTasks::PplstmtOptimize(pquery, pfUnexpectedFailure);
+	GPOS_TRY
+	{
+		return COptTasks::PplstmtOptimize(pquery, pfUnexpectedFailure);
+	}
+	GPOS_CATCH_EX(ex)
+	{
+		if (GPOS_MATCH_EX(ex, gpdxl::ExmaGPDB, gpdxl::ExmiGPDBError))
+		{
+		  elog(ERROR, "GPDB exception. Aborting GPORCA plan generation.");
+		}
+	}
+	GPOS_CATCH_END;
+	return NULL;
 }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f6b76472/src/backend/gpopt/gpdbwrappers.cpp
----------------------------------------------------------------------
diff --git a/src/backend/gpopt/gpdbwrappers.cpp b/src/backend/gpopt/gpdbwrappers.cpp
index 7d72823..1d6a071 100644
--- a/src/backend/gpopt/gpdbwrappers.cpp
+++ b/src/backend/gpopt/gpdbwrappers.cpp
@@ -237,8 +237,13 @@
 
 #define GP_WRAP_END	\
 		}	\
+		else \
+		{ \
+			EmitErrorReport(); \
+			FlushErrorState(); \
+			GPOS_RAISE(gpdxl::ExmaGPDB, gpdxl::ExmiGPDBError); \
+		} \
 	}	\
-	GPOS_RAISE(gpdxl::ExmaGPDB, gpdxl::ExmiGPDBError)
 
 using namespace gpos;
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f6b76472/src/backend/gpopt/utils/COptTasks.cpp
----------------------------------------------------------------------
diff --git a/src/backend/gpopt/utils/COptTasks.cpp b/src/backend/gpopt/utils/COptTasks.cpp
index ca20e4c..58085b8 100644
--- a/src/backend/gpopt/utils/COptTasks.cpp
+++ b/src/backend/gpopt/utils/COptTasks.cpp
@@ -726,9 +726,11 @@ COptTasks::PdrgPssLoad
 	}
 	GPOS_CATCH_EX(ex)
 	{
-		GPOS_RESET_EX;
-
+		if (GPOS_MATCH_EX(ex, gpdxl::ExmaGPDB, gpdxl::ExmiGPDBError)) {
+			GPOS_RETHROW(ex);
+		}
 		elog(DEBUG2, "\n[OPT]: Using default search strategy");
+		GPOS_RESET_EX;
 	}
 	GPOS_CATCH_END;
 
@@ -1528,13 +1530,6 @@ COptTasks::PvEvalExprFromDXLTask
 		{
 			CMDCache::Shutdown();
 		}
-		// Catch GPDB exceptions
-		if (GPOS_MATCH_EX(ex, gpdxl::ExmaGPDB, gpdxl::ExmiGPDBError))
-		{
-			elog(NOTICE, "Found non const expression. Please check log for more information.");
-			GPOS_RESET_EX;
-			return NULL;
-		}
 		if (FErrorOut(ex))
 		{
 			IErrorContext *perrctxt = CTask::PtskSelf()->Perrctxt();

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f6b76472/src/test/regress/expected/abstime_optimizer.out
----------------------------------------------------------------------
diff --git a/src/test/regress/expected/abstime_optimizer.out b/src/test/regress/expected/abstime_optimizer.out
new file mode 100644
index 0000000..81b6fbd
--- /dev/null
+++ b/src/test/regress/expected/abstime_optimizer.out
@@ -0,0 +1,137 @@
+--
+-- ABSTIME
+-- testing built-in time type abstime
+-- uses reltime and tinterval
+--
+--
+-- timezones may vary based not only on location but the operating
+-- system.  the main correctness issue is that the OS may not get 
+-- daylight savings time right for times prior to Unix epoch (jan 1 1970).
+--
+CREATE TABLE ABSTIME_TBL (f1 abstime);
+NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'f1' as the Greenplum
Database data distribution key for this table.
+HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s)
chosen are the optimal data distribution key to minimize skew.
+BEGIN;
+INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'now');
+INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'now');
+SELECT count(*) AS two FROM ABSTIME_TBL WHERE f1 = 'now' ;
+ two 
+-----
+   2
+(1 row)
+
+END;
+DELETE FROM ABSTIME_TBL;
+INSERT INTO ABSTIME_TBL (f1) VALUES ('Jan 14, 1973 03:14:21');
+INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'Mon May  1 00:30:30 1995');
+INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'epoch');
+INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'infinity');
+INSERT INTO ABSTIME_TBL (f1) VALUES (abstime '-infinity');
+INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'May 10, 1947 23:59:12');
+-- what happens if we specify slightly misformatted abstime? 
+INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 35, 1946 10:00:00');
+ERROR:  date/time field value out of range: "Feb 35, 1946 10:00:00"
+LINE 1: INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 35, 1946 10:00:00'...
+                                             ^
+HINT:  Perhaps you need a different "datestyle" setting.
+INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10');
+ERROR:  date/time field value out of range: "Feb 28, 1984 25:08:10"
+LINE 1: INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10'...
+                                             ^
+-- badly formatted abstimes:  these should result in invalid abstimes 
+INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format');
+ERROR:  invalid input syntax for type abstime: "bad date format"
+LINE 1: INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format');
+                                             ^
+INSERT INTO ABSTIME_TBL (f1) VALUES ('Jun 10, 1843');
+ERROR:  cannot convert abstime "invalid" to timestamp
+ERROR:  GPDB exception. Aborting GPORCA plan generation. (CGPOptimizer.cpp:66)
+-- test abstime operators
+SELECT '' AS eight, * FROM ABSTIME_TBL ORDER BY 2;
+ eight |              f1              
+-------+------------------------------
+       | -infinity
+       | Sat May 10 23:59:12 1947 PST
+       | Wed Dec 31 16:00:00 1969 PST
+       | Sun Jan 14 03:14:21 1973 PST
+       | Mon May 01 00:30:30 1995 PDT
+       | infinity
+(6 rows)
+
+SELECT '' AS six, * FROM ABSTIME_TBL
+   WHERE ABSTIME_TBL.f1 < abstime 'Jun 30, 2001' ORDER BY 2;
+ six |              f1              
+-----+------------------------------
+     | -infinity
+     | Sat May 10 23:59:12 1947 PST
+     | Wed Dec 31 16:00:00 1969 PST
+     | Sun Jan 14 03:14:21 1973 PST
+     | Mon May 01 00:30:30 1995 PDT
+(5 rows)
+
+SELECT '' AS six, * FROM ABSTIME_TBL
+   WHERE ABSTIME_TBL.f1 > abstime '-infinity' ORDER BY 2;
+ six |              f1              
+-----+------------------------------
+     | Sat May 10 23:59:12 1947 PST
+     | Wed Dec 31 16:00:00 1969 PST
+     | Sun Jan 14 03:14:21 1973 PST
+     | Mon May 01 00:30:30 1995 PDT
+     | infinity
+(5 rows)
+
+SELECT '' AS six, * FROM ABSTIME_TBL
+   WHERE abstime 'May 10, 1947 23:59:12' <> ABSTIME_TBL.f1 ORDER BY 2;
+ six |              f1              
+-----+------------------------------
+     | -infinity
+     | Wed Dec 31 16:00:00 1969 PST
+     | Sun Jan 14 03:14:21 1973 PST
+     | Mon May 01 00:30:30 1995 PDT
+     | infinity
+(5 rows)
+
+SELECT '' AS three, * FROM ABSTIME_TBL
+   WHERE abstime 'epoch' >= ABSTIME_TBL.f1 ORDER BY 2;
+ three |              f1              
+-------+------------------------------
+       | -infinity
+       | Sat May 10 23:59:12 1947 PST
+       | Wed Dec 31 16:00:00 1969 PST
+(3 rows)
+
+SELECT '' AS four, * FROM ABSTIME_TBL
+   WHERE ABSTIME_TBL.f1 <= abstime 'Jan 14, 1973 03:14:21' ORDER BY 2;
+ four |              f1              
+------+------------------------------
+      | -infinity
+      | Sat May 10 23:59:12 1947 PST
+      | Wed Dec 31 16:00:00 1969 PST
+      | Sun Jan 14 03:14:21 1973 PST
+(4 rows)
+
+SELECT '' AS four, * FROM ABSTIME_TBL
+  WHERE ABSTIME_TBL.f1 <?>
+	tinterval '["Apr 1 1950 00:00:00" "Dec 30 1999 23:00:00"]' ORDER BY 2;
+ four |              f1              
+------+------------------------------
+      | Wed Dec 31 16:00:00 1969 PST
+      | Sun Jan 14 03:14:21 1973 PST
+      | Mon May 01 00:30:30 1995 PDT
+(3 rows)
+
+SELECT '' AS four, f1 AS abstime,
+  date_part('year', f1) AS year, date_part('month', f1) AS month,
+  date_part('day',f1) AS day, date_part('hour', f1) AS hour,
+  date_part('minute', f1) AS minute, date_part('second', f1) AS second
+  FROM ABSTIME_TBL
+  WHERE isfinite(f1)
+ ORDER BY abstime;
+ four |           abstime            | year | month | day | hour | minute | second 
+------+------------------------------+------+-------+-----+------+--------+--------
+      | Sat May 10 23:59:12 1947 PST | 1947 |     5 |  10 |   23 |     59 |     12
+      | Wed Dec 31 16:00:00 1969 PST | 1969 |    12 |  31 |   16 |      0 |      0
+      | Sun Jan 14 03:14:21 1973 PST | 1973 |     1 |  14 |    3 |     14 |     21
+      | Mon May 01 00:30:30 1995 PDT | 1995 |     5 |   1 |    0 |     30 |     30
+(4 rows)
+

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f6b76472/src/test/regress/expected/errors.out
----------------------------------------------------------------------
diff --git a/src/test/regress/expected/errors.out b/src/test/regress/expected/errors.out
index 2e53cdc..ebb70aa 100755
--- a/src/test/regress/expected/errors.out
+++ b/src/test/regress/expected/errors.out
@@ -483,9 +483,13 @@ create function infinite_recurse() returns int as
 -- # mpp-2756
 -- m/(ERROR|WARNING|CONTEXT|NOTICE):.*stack depth limit exceeded\s+at\s+character/
 -- s/\s+at\s+character.*//
+-- m/ERROR:.*GPDB exception. Aborting GPORCA.*/
+-- s/ERROR:.*GPDB exception. Aborting GPORCA.*//
 -- end_matchsubs
+-- start_ignore
 select infinite_recurse();
 ERROR:  stack depth limit exceeded
+-- end_ignore
 select 1; -- test that this works
  ?column? 
 ----------

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f6b76472/src/test/regress/expected/gp_optimizer.out
----------------------------------------------------------------------
diff --git a/src/test/regress/expected/gp_optimizer.out b/src/test/regress/expected/gp_optimizer.out
index fd3a686..4da8197 100644
--- a/src/test/regress/expected/gp_optimizer.out
+++ b/src/test/regress/expected/gp_optimizer.out
@@ -8730,6 +8730,41 @@ drop role unpriv;
 drop table can_set_tag_target;
 drop table can_set_tag_audit;
 
+reset optimizer_segments;
+-- Check if ORCA can handle GPDB's error properly
+drop table if exists orca_exc_handle;
+NOTICE:  table "orca_exc_handle" does not exist, skipping
+create table orca_exc_handle(
+	a int primary key,
+	b char
+);
+NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "orca_exc_handle_pkey" for
table "orca_exc_handle"
+insert into orca_exc_handle select i, i from generate_Series(1,4) as i; 
+-- enable the fault injector
+--start_ignore
+\! gpfaultinjector -f opt_relcache_translator_catalog_access -y error --seg_dbid 1
+20160425:14:59:22:001357 gpfaultinjector:krajaraman:krajaraman-[INFO]:-Starting gpfaultinjector
with args: -f opt_relcache_translator_catalog_access -y error --seg_dbid 1
+20160425:14:59:22:001357 gpfaultinjector:krajaraman:krajaraman-[INFO]:-local Greenplum Version:
'postgres (Greenplum Database) 4.3.99.00 build dev'
+20160425:14:59:22:001357 gpfaultinjector:krajaraman:krajaraman-[INFO]:-Obtaining Segment
details from master...
+20160425:14:59:22:001357 gpfaultinjector:krajaraman:krajaraman-[INFO]:-Injecting fault on
1 segment(s)
+20160425:14:59:22:001357 gpfaultinjector:krajaraman:krajaraman-[INFO]:-Injecting fault on
krajaraman:/Users/krajaraman/gitdev/gpdb64/gpAux/gpdemo/datadirs/qddir/demoDataDir-1:content=-1:dbid=1:mode=s:status=u
+20160425:14:59:22:001357 gpfaultinjector:krajaraman:krajaraman-[INFO]:-DONE
+--end_ignore
+select a from orca_exc_handle;
+ERROR:  fault triggered, fault name:'opt_relcache_translator_catalog_access' fault type:'error'
(faultinjector.c:671)
+ERROR:  GPDB exception. Aborting GPORCA plan generation. (CGPOptimizer.cpp:66)
+-- reset the fault injector
+--start_ignore
+\! gpfaultinjector -f opt_relcache_translator_catalog_access -y reset --seg_dbid 1
+20160425:14:59:23:001374 gpfaultinjector:krajaraman:krajaraman-[INFO]:-Starting gpfaultinjector
with args: -f opt_relcache_translator_catalog_access -y reset --seg_dbid 1
+20160425:14:59:23:001374 gpfaultinjector:krajaraman:krajaraman-[INFO]:-local Greenplum Version:
'postgres (Greenplum Database) 4.3.99.00 build dev'
+20160425:14:59:23:001374 gpfaultinjector:krajaraman:krajaraman-[INFO]:-Obtaining Segment
details from master...
+20160425:14:59:23:001374 gpfaultinjector:krajaraman:krajaraman-[INFO]:-Injecting fault on
1 segment(s)
+20160425:14:59:23:001374 gpfaultinjector:krajaraman:krajaraman-[INFO]:-Injecting fault on
krajaraman:/Users/krajaraman/gitdev/gpdb64/gpAux/gpdemo/datadirs/qddir/demoDataDir-1:content=-1:dbid=1:mode=s:status=u
+20160425:14:59:23:001374 gpfaultinjector:krajaraman:krajaraman-[INFO]:-DONE
+--end_ignore
+drop table orca_exc_handle;
+-- End of Check if ORCA can handle GPDB's error properly
 -- clean up
 drop schema orca cascade;
 NOTICE:  drop cascades to table orca.bm_dyn_test_onepart_1_prt_part5

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f6b76472/src/test/regress/expected/horology.out
----------------------------------------------------------------------
diff --git a/src/test/regress/expected/horology.out b/src/test/regress/expected/horology.out
index 4b79ed8..9786e5a 100755
--- a/src/test/regress/expected/horology.out
+++ b/src/test/regress/expected/horology.out
@@ -10,8 +10,9 @@ INSERT INTO ABSTIME_HOROLOGY_TBL (f1) VALUES ('Jan 14, 1973 03:14:21'),
 (abstime 'epoch'),
 (abstime 'infinity'),
 (abstime '-infinity'),
-(abstime 'May 10, 1947 23:59:12'),
-('Jun 10, 1843');
+(abstime 'May 10, 1947 23:59:12');
+-- orca will fail for this
+INSERT INTO ABSTIME_HOROLOGY_TBL (f1) VALUES('Jun 10, 1843');
 CREATE TABLE INTERVAL_HOROLOGY_TBL (f1 interval);
 NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'f1' as the Greenplum
Database data distribution key for this table.
 HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s)
chosen are the optimal data distribution key to minimize skew.


Mime
View raw message