0

Is there a way to create a C++ program to rewrite a query in an optimal form without the use of a database such as storing information in arrays. 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.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by drkybelk
0

How do you decide that a certain restriction is needed and another is not? It's not obvious from the query and that makes it difficult for any compiler do decide what can be optimised away and what not. Optimisations of queries are best done within the database. Most major DB systems have dedicated profilers and optimisers. For optimisations not only table definitions are taken into account, but also indices, actual tablesizes or table size hints and other things. It would be difficult to wrtie a "dry-run-optimiser" in C++ or any other language for that matter. Your best bet would probably be LINQ of C# fame, but that would hold links or copies of DB objects.
If that does not answer your question or if you were actually after something else then please re-phrase the question and we'll try to help.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.