This paper presents a query optimizer module based on cost estimation that chooses the best filtering step algorithm to perform a specific spatial join operation. A set of expressions to predict the number of I/O operations and the response time of each algorithm is first presented and later refined considering a given hardware configuration. The query optimizer chooses the algorithm that returns the smaller estimated response time. In order to evaluate the query optimizer, we carried out a set of tests with synthetic and real data sets, in a significant number of different scenarios. The query optimizer correctly chooses the fastest algorithm in almost 90% of submitted operations, with minimal overhead. Categories and Subject Descriptors H.2 [DATABASE MANAGEMENT]: Database applications--Spatial databases and GIS; H.2 [DATABASE MANAGEMENT ]: Physical Design--Access methods General Terms Algorithms, Performance Keywords Spatial databases and GIS, Query processing, Access methods