db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael.Kashamb...@bmwna.com
Subject RE: Exclusive Criteria OR Conditions
Date Wed, 21 Jul 2004 16:38:04 GMT
If you look at how Torque geenrates or condition when you add one Criterion
as an OR condition to another, it looks something like the following:

for criteria A, B, C

depending on the order in which you add the conditions, you could end up
with 

( ( A or B ) or C )

or 

( A or ( B or C ) ).

How are we to know in what order the database processes these OR conditions
when some are defined in parentheses?  Is processing alwasys left to right
or does it process parenthesized conditions first.

This can have a significant effect on performance especially if your A
criterion uses indexing (i.e. if your first criterion which is indexed finds
a match, it should not attempt to evaluate any other conditions).  So, in
case 2, would the database evaluate ( B or C ) before evaluating criterion
A?

I would have preferred to construct OR conditions by adding them to the
top-level criteria so that I can have

A or B or C

Michael

-----Original Message-----
From: ron piterman [mailto:ron.piterman@gmx.net]
Sent: Wednesday, July 21, 2004 5:00 AM
To: torque-user@db.apache.org
Subject: Re: Exclusive Criteria OR Conditions


I don't have much expreince with Torque, but did you think of:

function Criterion or(List rules) {
	List temp = new Vector();
	for (int i = 0; i < rules.size(); i++) {
		
		Criterion c = createCriterion(rules.get(i));
		if (i > 0)
			((Criterion)temp.get(i-1)).or(c);
		temp.add(c);
	}
	return (Criterion)temp.get(0);
}

now the createCriterion method is missing, but one can figure...

Cheers,
Ron


Michael.Kashambuzi@bmwna.com wrote:
> I've already checked in the mailing list and have not found an answer.
> 
> Does anyone know how to perform an OR in the following situation.
> 
> 	SELECT A, B, C
> 	FROM TABLE1
> 	WHERE A IN (1,2,3) OR B IN (4,5,6) OR D in (7,8,9)
> 
> For each criterion, I want to add it as a criterion to the main Criteria
> object and not as a criterion for a preexisting criterion.
> 
> 	Criterion1: A IN (1,2,3) 
> 	Criterion2: B IN (4,5,6) 
> 	Criterion3: D in (7,8,9)
> 
> I want to add each of the above criterion to the Criteria ndependently.  I
> don't want to add Criterion3 and as an OR to Critrion2 and the Criterion2
as
> an OR to Criterion1.
> 
> Most of my queries are dynamic in nature so I can't always assume the
order
> in which criteria are added.  I just need to provide n Criterion objects
and
> all all n independently as OR's to my main Criteria object.
> 
> Any ideas?
> 
> Thanks.
> 
> Michael



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message