You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Chema <ch...@gmail.com> on 2007/11/26 17:22:10 UTC

Simple doubt about performance

Hello:

I'm trying to make a simple query on two different tables.
This query has same fields but different table name. The query selector is
the PK field

My question is:

what is, in performance terms, the best solution: passing to query the table
name as parameter or make two queries with different table name each one ?

For example:

1)

<select id="getF" resultClass="java.sql.Timestamp" parameterClass="
java.util.HashMap">
    SELECT  FIELD
    FROM     $table$
    WHERE  PK= $pk$
  </select>

or

2)


<select id="getF_1" resultClass="java.sql.Timestamp" parameterClass="
java.lang.String">
    SELECT  FIELD
    FROM     A
    WHERE  PK= #pk#
  </select>

    <select id="getF_2" resultClass="java.sql.Timestamp" parameterClass="
java.lang.String">
     SELECT  FIELD
    FROM     B
    WHERE  PK= #pk#
  </select>



Thanks

Re: Simple doubt about performance

Posted by Larry Meadors <lm...@apache.org>.
#2 will on most platforms, because the statement will be
parameterized: #pk# vs $pk$

Other than that, they should be identical...with the exception that #1
will be vulnerable to SQL injection.

Larry


On Nov 26, 2007 9:22 AM, Chema <ch...@gmail.com> wrote:
>
> Hello:
>
> I'm trying to make a simple query on two different tables.
> This query has same fields but different table name. The query selector is
> the PK field
>
> My question is:
>
> what is, in performance terms, the best solution: passing to query the table
> name as parameter or make two queries with different table name each one ?
>
> For example:
>
> 1)
>
> <select id="getF" resultClass="java.sql.Timestamp"
> parameterClass="java.util.HashMap">
>      SELECT  FIELD
>      FROM     $table$
>      WHERE  PK= $pk$
>    </select>
>
> or
>
> 2)
>
>
> <select id="getF_1" resultClass="java.sql.Timestamp"
> parameterClass="java.lang.String">
>     SELECT  FIELD
>     FROM     A
>     WHERE  PK= #pk#
>   </select>
>
>     <select id="getF_2" resultClass="java.sql.Timestamp"
> parameterClass="java.lang.String">
>      SELECT  FIELD
>      FROM     B
>      WHERE  PK= #pk#
>   </select>
>
>
>
> Thanks
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>