<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % CustomDTD SYSTEM "../../../../../../docbook/custom.dtd">
%CustomDTD;
]>
<chapter id="prepared-statements">
    <title>Prepared Statements</title>
    
    <para>Teiid provides a standard implementation of <code>java.sql.PreparedStatement</code>.  PreparedStatements can be very important in speeding up common statement execution, since they allow the server to skip parsing, resolving, and planning of the statement.
    See the Java documentation for more information on <ulink url="http://download.oracle.com/javase/6/docs/technotes/guides/jdbc/getstart/preparedstatement.html#1000039">PreparedStatement usage</ulink>.
    </para>
    
    <itemizedlist>
    	<para><code>PreparedStatement</code> Considerations</para>
    	<listitem>
		    <para>It is not necessary to pool client side Teiid <code>PreparedStatements</code>, since Teiid performs plan caching on the server side.</para>	
    	</listitem>
    	<listitem>
    		<para>The number of cached plans is configurable (see the Admin Guide), and are purged by the least recently used (LRU).</para>
    	</listitem>
    	<listitem>
    		<para>Cached plans are not distributed through a cluster.  A new plan must be created for each cluster member.</para>
    	</listitem>
    	<listitem>
    		<para>Plans are cached for the entire VDB or for just a particular session.  The scope of a plan is detected automatically based upon the functions evaluated during it's planning process.</para>
    	</listitem>
    	<listitem>
    		<para>Stored procedures executed through a <code>CallableStatement</code> have their plans cached just as a <code>PreparedStatement</code>.</para>
    	</listitem>
    	<listitem>
    		<para>Bind variable types in function signatures, e.g. "where t.col = abs(?)" can be determined if the function has only one signature or if the function is used in a predicate where the return type can be determined.  
    		In more complex situations it may be necessary to add a type hint with a cast or convert, e.g. upper(convert(?, string)).</para>
    	</listitem>
    </itemizedlist>
    
</chapter>