Is there a way to create a program to rewrite a query in an optimal form. If so, how? What can I do to implement this.


Rewrite

SELECT EMPOYEE.EMPNO, POSITION
FROM EMPLOYEE E, JOBHISTORY J
WHERE E.EMPNO = J.EMPNO
AND STARTDATE <= ENDDATE
AND SALARY <= 3000

into

SELECT EMPLOYEE.EMPNO, POSITION
FROM EMPLOYEE E, JOBHISTORY J
WHERE E.EMPNO = J.EMPNO
AND SALARY <= 3000;


because "AND STARTDATE <= ENDDATE is not needed in the first query.

There is no rule of thumb to follow to optimize a query.

and what you are trying to do is not optimization, but removing some requirements.

How do you decide if a clause is needed in a query or not? If you have a rule for that, you can code it. But from your example this rule would have to rely on semantic knowledge rather on formal aspects of the query.

for optimizing query you must manage table structure, field type and relation ship with tables

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.