Have you tried something like: ``` select count(*) from treatments where treatmentId in (select treatmentid from vtreatments where vtreatments MATCH 'meshram' INTERSECT select treatmentid from vlocations where geopoly_within(_shape, poly) ; ``` By the way, you can use .eqp on so that you do not need to issue the same SQL statement twice to get the EXPLAIN QUERY PLAN output together with the results.