Hi!
The problem is that the function executes on the segments, but it also
tries to access the table 'gaia_source_2m'. That's not allowed in GPDB,
because when the function runs on one segment, it won't see the rows
that reside on the other segments. A couple of things you could try to
work around that:
1. If the 'gaiadr2.gaia_source_2m' table isn't too large, you could
change it into a replicated table.
ALTER TABLE gaiadr2.gaia_source_2m SET DISTRIBUTED REPLICATED;
Replicated tables can be accessed by functions on all segments.
2. The get_ra function takes 'p_source_id' and 'p_table' as arguments,
so that it can fetch that row from the given table. You could pass that
whole row to the function as argument, instead. That would be faster
anyway, as you already have that row available in the surrounding query.
So something like this:
create or replace function get_ra(m gaiadr2.gaia_source_2m)
returns double precision
as $$
select lat(EPOCH_PROP_POS(m.ra, m.dec, m.parallax, m.pmra, m.pmdec,
m.radial_velocity, 2015.5, 2000))
$$ language sql stable;
And formulate the query as:
SELECT
k.id, gdr2.source_id AS iddr2
FROM euclid.kids_dr4 AS k,
gaiadr2.gaia_source_2M AS gdr2
WHERE q3c_join(get_ra(gdr2.*),get_dec(gdr2.*), k.raj2000::double
precision, k.decj2000::double
precision, 0.5/3600);
This is completely untested as I don't have the full schema, so it's
probably not quite right, but you get the idea. And I assume that
get_dec() similar refactoring as get_ra().
- Heikki