regions has 5 rows and customers has 1,000 rows with an index idx_customers_region on region_id. To list the customers of the region named 'EU', the efficient plan is:
regions table and find EU,idx_customers_region to fetch only that region's customers.SQLite normally finds this plan by itself, but in a CROSS JOIN it will never reorder the tables, so you can dictate the loop order yourself.
Write the query with CROSS JOIN so that regions is the outer loop and customers the inner, index-driven loop. Return only the customer name. Do not use table aliases (so the plan text stays readable).
nameregions CROSS JOIN customers ON ... (outer loop regions)customers must be searched through idx_customers_regionIn SQLite the left table of a CROSS JOIN is always the outer loop.
Put the matching condition in ON customers.region_id = regions.id and the filter in WHERE regions.name = 'EU'.
No results yet
Run your code to check it against the examples, or submit to run every test.