Techniques for sharing cursors are provided. When a new query is issued, a
database server determines whether the new query is semantically
equivalent to a previous query. If so, then database server computes
statistics associated with the new query. Based on the statistics, the
database server determines whether compiling the new query would produce
an execution plan that satisfies certain criteria. If so, then the cursor
is used to execute the new query. In another approach, one cursor sharing
technique (CST) is used to determine which cursor to use to execute a
first set of semantically-equivalent queries. Statistics are gathered
during execution of the first set of queries. The database server
determines, based on the statistics, when to switch from using the first
CST to a different CST. The different CST is used to determine which
cursor to use to execute a second set of queries that are
semantically-equivalent to the first set.