Posts

Showing posts from 2014

Logical order of SQL Query execution

First of all we should know that logical and physical order of query execution are different but result must be the same. Every RDBMS can optimize the order in which parts of query are executed for performance reason. However that rearrangement must not influence the final result. The query must return the same records as if it is executed in this logical order:     FROM     WHERE     GROUP BY     HAVING     SELECT     DISTINCT     ORDER BY     TOP X / LIMIT X/ select * from ( subquery ) ROWNUM <= X The programmers should always be aware of this sequence in order not to fall into a trap. A common mistake is to try using column alias in GROUP BY, WHERE and HAVING clause but actually it is possible to use it only after SELECT clause is executed (ORDER BY and TOP/LIMIT/that long stupid oracle boilerplate). Another mistake is to try sorting by column  that is not listed in SELECT clause. The less common but hard to debug problem could be made if OUTER JOIN is used

SQL Fiddle

If you need fast try and error check against some of the most popular relational database management system  SQL Fiddle is the wright address. It is also free as in beer :) It is an online application in which you can select to work some of supported RDBMS. There are 2 text area fields: first is used to set your schema and data, the second is used to write some query that will run against your schema and data. Using SQL Fiddle you can share your script similar to Gist for source code sharing. It is also useful as online SQL code beautifier and formatter. Here is an example of SQL Code for Oracle DB: http://sqlfiddle.com/#!4/1897b/1

XMLUnit

XMLUnit for Java provides a set of supporting classes (e.g. Diff,  DetailedDiff, Transform, SimpleXpathEngine, Validator,NodeTest) that allow assertions to be made about: The differences between two pieces of XML The outcome of transforming a piece of XML using XSLT The evaluation of an XPath expression on a piece of XML The validity of a piece of XML Individual nodes in a piece of XML that are exposed by DOM Traversal XMLUnit for Java can also treat HTML content (even badly-formed HTML) as valid XML to allow these assertions to be made about the content of web pages too.   Experience I've used XMLUnit in 2 situations: assert that 2 xml files are semantically the same regardless of structural differences (eg. different formatting, different namespace prefixes, usage of opening and closing tag vs. empty tag...) and finding real differences between two xml files regardless of prior mentioned differences in structure. The equality of two