'Maria DB HTML-Like Syntax: <#if foo> bar </#if>

Looking at some SQL query files (.sql) used by the DAO of a java application meant for MariaDB and found these syntaxes

        <#if foo>
            RIGHT JOIN bar AS b .....       
        </#if>

While I know that these are conditional statements, I am not sure why the HTML-like (<#> </>)tags are used for it. I know that if statements can be written without them in SQL. Not sure if this is a MariaDB thing or just an esoteric SQL syntax since my quick Google search didn't produce answer.



Solution 1:[1]

Thanks to @a_horse_with_no_name for the hint, it led me in the right direction. The syntax is from Freemarker. They were writing the SQL query as Freemarker templates. The template gets processed by Freemarker and the resulting query is what is fed to the PreparedStatement for DB's use.

Why would they do that? My guess is that since the SQL files are huge (100s of lines), it will reduce latency. Instead of having the DB process all the conditionals, the template processor (Freemarker) does that and the resulting query is the exact one needed by the DB for the situation. Processing by Freemarker is "cheaper" than DB's.

UPDATE: On second thought, I am not sure if that is a good practice/design because it makes the query hard to follow. I will be interested to know what people think.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1