I have a large entity-attribute-value like a table. I try to select some rows from this table with a subquery and then filtrate with rows. How can I prevent merging subquery and main query in this situation?
For example:
EMP:
EMPNO | ENAME | SAL
---------------------
1000 | KING | 10000
1001 | BLAKE | 7500
CREATE VIEW EAV(ID,ATTR,VALUE) AS
select empno, 'name'||ename, ename from emp -- subquery 1
union
select empno, 'sal'||ename, ename from emp -- subquery 2
union
select empno, 'mgr'||ename, ename from emp -- subquery 3
NOTE: ||ename
was added just to prevent Oracle to optimize next queries by adding filter "(null is not null)" to subquery 1 and 3
In subquery I select all rows with attribute 'sal%' and then filtrate it in the main query:
select *
FROM (select id,value from EAV where attr like 'sal%')
WHERE to_number(value) > 5000;
This query fall cause optimizer merge subquery with outer query. After merging DB try to apply to_number to all values in column "value", but some of it has a string value. Witch HINT prevent this optimization?
p.s. I want to get same result as
WITH t as (
select /*+ materialize */ id,value
from eav
where attr like 'sal%')
select * from t where to_number(value) > 5000;
but, without CTE.