blob: e60f3b048b77e091a4e938d4ac6a02f03bd02c63 [file]
--
-- ORCA tests which require gp_fault_injector
--
CREATE SCHEMA gporca_faults;
SET search_path = gporca_faults, public;
CREATE TABLE foo (a int, b int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Apache Cloudberry 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.
INSERT INTO foo VALUES (1,1);
-- test interruption requests to optimization
select gp_inject_fault('opt_relcache_translator_catalog_access', 'reset', 1);
gp_inject_fault
-----------------
Success:
(1 row)
select gp_inject_fault('opt_relcache_translator_catalog_access', 'interrupt', 1);
gp_inject_fault
-----------------
Success:
(1 row)
select count(*) from foo;
count
-------
1
(1 row)
-- Ensure that ORCA is not called on any process other than the master QD
CREATE FUNCTION func1_nosql_vol(x int) RETURNS int AS $$
BEGIN
RETURN $1 +1;
END
$$ LANGUAGE plpgsql VOLATILE;
-- Query that runs the function on an additional non-QD master slice
-- Include the EXPLAIN to ensure that this happens in the plan.
EXPLAIN SELECT * FROM func1_nosql_vol(5), foo;
QUERY PLAN
-------------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=10000000000.25..10000000001.34 rows=3 width=12)
-> Nested Loop (cost=10000000000.25..10000000001.30 rows=1 width=12)
-> Broadcast Motion 1:3 (slice2) (cost=0.25..0.28 rows=1 width=4)
-> Function Scan on func1_nosql_vol (cost=0.25..0.26 rows=1 width=4)
-> Seq Scan on foo (cost=0.00..1.01 rows=1 width=8)
Optimizer: Postgres query optimizer
(6 rows)
select gp_inject_fault('opt_relcache_translator_catalog_access', 'reset', 1);
gp_inject_fault
-----------------
Success:
(1 row)
select gp_inject_fault('opt_relcache_translator_catalog_access', 'interrupt', 1);
gp_inject_fault
-----------------
Success:
(1 row)
SELECT * FROM func1_nosql_vol(5), foo;
func1_nosql_vol | a | b
-----------------+---+---
6 | 1 | 1
(1 row)
-- The fault should *not* be hit above when optimizer = off, to reset it now.
SELECT gp_inject_fault('opt_relcache_translator_catalog_access', 'reset', 1);
gp_inject_fault
-----------------
Success:
(1 row)
-- Test to check that GPOPTOptimizedPlan() does not cause std::terminate() by throwing an uncaught exception.
CREATE TABLE test_orca_uncaught_exc(a int, b int) DISTRIBUTED RANDOMLY;
-- Since ORCA cannot optimize this query, an exception is generated. We then inject a second exception when the
-- first is caught and verify that it is not propagated further (no std::terminate() is called and backend is alive).
SELECT gp_inject_fault('opt_clone_error_msg', 'skip', 1);
gp_inject_fault
-----------------
Success:
(1 row)
SELECT sum(distinct a), count(distinct b) FROM test_orca_uncaught_exc;
sum | count
-----+-------
| 0
(1 row)
SELECT gp_inject_fault('opt_clone_error_msg', 'reset', 1);
gp_inject_fault
-----------------
Success:
(1 row)
-- start_ignore
DROP TABLE test_orca_uncaught_exc;
-- end_ignore