db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-4346) LIKE with parameter recomputes greaterEqualString and lessThanString way too often
Date Tue, 11 Aug 2009 10:27:14 GMT

    [ https://issues.apache.org/jira/browse/DERBY-4346?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12741794#action_12741794
] 

Knut Anders Hatlen commented on DERBY-4346:
-------------------------------------------

Here's a simpler query to illustrate the problem. I made greaterEqualStringFromParameterWithEsc()
and lessThanStringFromParameterWithEsc() print a line each time they're called and executed
a query which performed a nested join with a LIKE clause restricting the inner table. It looks
like greaterEqualString and lessThanString are recomputed once for every row in the outer
table. I'd guess this is because the inner result set is reopened for each row in the outer
table.

ij> create table t (x varchar(10) unique not null);
0 rows inserted/updated/deleted
ij> insert into t values 'abc','def','ghi';
3 rows inserted/updated/deleted
ij> prepare ps as 'select * from --derby-properties joinOrder=FIXED
t t1, t t2 where t2.x like ? escape ''x''';
ij> execute ps using 'values ''___''';
IJ WARNING: Autocommit may close using result set
greaterEqualStringFromParameterWithEsc(___, x, 10)
lessThanStringFromParameterWithEsc(___, x, 10)
X         |X         
---------------------
abc       |abc       
abc       |def       
abc       |ghi       
greaterEqualStringFromParameterWithEsc(___, x, 10)
lessThanStringFromParameterWithEsc(___, x, 10)
def       |abc       
def       |def       
def       |ghi       
greaterEqualStringFromParameterWithEsc(___, x, 10)
lessThanStringFromParameterWithEsc(___, x, 10)
ghi       |abc       
ghi       |def       
ghi       |ghi       

9 rows selected
ij>

> LIKE with parameter recomputes greaterEqualString and lessThanString way too often
> ----------------------------------------------------------------------------------
>
>                 Key: DERBY-4346
>                 URL: https://issues.apache.org/jira/browse/DERBY-4346
>             Project: Derby
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions: 10.5.1.1
>            Reporter: Knut Anders Hatlen
>
> I profiled a 7-way join (the exact query can be found here: http://src.opensolaris.org/source/xref/opengrok/trunk/src/org/opensolaris/opengrok/history/JDBCHistoryCache_queries.properties?r=809%3Abdef8b63f333#82
) and saw that 40% of the time was spent in Like.greaterEqualStringFromParameterWithEsc()
and Like.lessThanStringFromParameterWithEsc().
> These methods are used to generate "x >= greaterEqualString" and "x < lessThanString"
clauses that enable a "LIKE ?" clause to make use of indexes. Since the value of the ? parameter
is constant throughout a single execution of the statement, it should only be necessary to
invoke these methods once per LIKE clause per execution. They are clearly called more frequently
for the query in question, and reducing the number of invocations to one per execution would
probably make the query execute almost twice as fast.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message