Buenas días lista, Tengo estas tablas de ejemplo
create table TR ( cod NUMBER(8) not null, dat DATE not null ) ; create table TL ( cod NUMBER(8) not null, des VARCHAR2(1000) ) ; y ejecutando queries del estilo: select * from TL L WHERE EXISTS ( SELECT 'x' FROM TR R WHERE l.cod = r.cod and dat >= trunc(now() - 110) and dat <= trunc(now() - 10) ); consigo planes de ejecución usando semi join ( hash semi join ), que según entiendo va a ser el plan de ejecución óptimo en consultas usando exists cuando ambas tablas están en postgresql. El problema aparece cuando tengo la tabla TR en oracle y TL en postgresql, que tanto si uso dblink, dblink_ora o fdw no consigo el uso de semi join, sino Foreign Scan que entiendo que son equivalentes a seq scans. Las estadísticas entre oracle y postgresql, entiendo que no se están intercambiando, ¿ no?, cuando uso dblink y dblink_ora. También he intentado usar la opción, plan_costs, del fdw de oracle (https://github.com/laurenz/oracle_fdw) pero el plan de ejecución tampoco mejora. ¿ pensáis que puede mejorarse el plan de ejecución de está query ? explain ( analyze true, verbose true, costs true, buffers true, timing true ) select * from TL L WHERE EXISTS ( SELECT cod FROM TR@dblink R WHERE l.cod = r.cod and dat >= trunc(sysdate - 10) and dat <= trunc(sysdate - 5) ) "Seq Scan on tl l (cost=0.00..161529.00 rows=5000 width=1009) (actual time=65.570..111324.374 rows=50 loops=1)" " Output: l.cod, l.des" " Filter: (SubPlan 1)" " Rows Removed by Filter: 9950" " Buffers: shared hit=1429" " SubPlan 1" " -> Foreign Scan on pg_temp_6._dblink_tr_1 r (cost=15.00..25.00 rows=10 width=0) (actual time=11.125..11.125 rows=0 loops=10000)" " Filter: (l.cod = r.cod)" " Rows Removed by Filter: 50" " Remote Query: SELECT cod, NULL FROM tr WHERE (dat >= trunc((sysdate - 10))) AND (dat <= trunc((sysdate - 5)))" "Planning time: 0.714 ms" "Execution time: 111326.661 ms" usando dblink_ora_record: explain ( analyze true, verbose true, costs true, buffers true, timing true ) select * from TL L WHERE EXISTS ( SELECT cod FROM (select cod, dat from ( select * FROM dblink_ora_record('TEST', 'select cod, dat from TR') AS TR_LOCAL(cod number, dat timestamp) )) R WHERE l.cod = r.cod and dat >= trunc(sysdate - 10) and dat <= trunc(sysdate - 5) ); "Seq Scan on tl l (cost=0.00..326554.00 rows=5000 width=1009) (actual time=214.223..16124.594 rows=50 loops=1)" " Output: l.cod, l.des" " Filter: (SubPlan 1)" " Rows Removed by Filter: 9950" " Buffers: shared hit=1429" " SubPlan 1" " -> Function Scan on pg_catalog.dblink_ora_record tr_local (cost=0.00..32.50 rows=1 width=0) (actual time=1.611..1.611 rows=0 loops=10000)" " Function Call: dblink_ora_record('TEST'::text, 'select cod, dat" "from TR'::text)" " Filter: ((l.cod = tr_local.cod) AND (tr_local.dat >= trunc((sysdate - 10))) AND (tr_local.dat <= trunc((sysdate - 5))))" " Rows Removed by Filter: 9972" "Planning time: 0.413 ms" "Execution time: 16124.760 ms" Un saludo - Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda@postgresql.org) Para cambiar tu suscripci�n: http://www.postgresql.org/mailpref/pgsql-es-ayuda