ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jiming Liu <jiming...@gmail.com>
Subject Re: Performance & SQL Formatting Issue
Date Tue, 03 Feb 2009 05:22:47 GMT
Hi Clinton,

I suppose formatted sql is slow might be caused by database engine waste
time to parse the white space, not only \r,\n,\t, but ' ' as well. And
actually ' ' is more than the other three white in real world.

So I recommend following code,


    public static String tidySql(String sql) {
        String[] values = sql.split("\\n");
        for (int i = 0; i < values.length; i++) {
            values[i] = values[i].trim();
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < values.length; i++) {
            sb.append(values[i]).append(' ');
        }
        return sb.toString();
    }

This code would reduce the size of the formatted sql, and should be helpful.


Best regards,

Jiming


On Tue, Feb 3, 2009 at 3:41 AM, Clinton Begin <clinton.begin@gmail.com>wrote:

> This is a good summary.  I've been watching the other thread.
>
> I think I might have found a possible candidate:
>
> public class SqlText implements SqlChild {
>  //...
>  public void setText(String text) {
>    this.text = text.replace('\r', ' ').replace('\n', ' ').replace('\t', '
> ');
>    this.isWhiteSpace = text.trim().length() == 0;
>  }
>  //...
> }
>
> I'll have to wait to get home to check to see if this is called on
> each execution, instead of just once at SQL mapper build time.
>
> Cheers,
> Clinton
>

Mime
View raw message