News combit Dev Blog

Filtering at Database Level

Posted: Friday, April 11, 2014 | 0 comment(s)
 
Using report parameters has become very popular since we've introduced them in version 19. A typical use case that will become even more seminal with version 20 of our reporting tool is using parameters to filter data (see last feature focus). This is something we've usually put on the "don't" list as databases can filter data much faster than we can. In the past, all records had to be passed to the reporting engine which then decided if a record should be used or not. A vast overhead for a task databases are usually optimized for. In version 20, we'll be introducing a new feature that allows List & Label filter expressions to be translated to native database filters, therefore hugely increasing performance (in principle, depending on the data this is "infinitely" faster).

This feature is supported out of the box by our .NET component. All SQL based DataProviders (SQL Server, Oracle, DB2, PostgreSQL, MySql, SQLite, RSS Bus, Firebird, NuoDB and DbConnectionDataProvider descendants) as well as the AdoDataProvider and XmlDataProvider classes offer thorough support for this feature. We’ll probably be able to add support for the ODataDataProvider as well before the release.
The syntax of a filter expression defined on a table is analyzed and translated to native statements. For SQL, of course, typical traps like SQL injection attack vectors are taken into account. The result of a translated filter is a parametrized SQL WHERE statement. The ADO.NET provider uses RowFilter functions and XML filtering is performed via highly optimized pre-compiled XPath expressions.
 
There are three different modes for a filter:
 
a) Full compatibility to database. Many of the built in functions can be fully translated to native database statements. For the SQL filters, this includes most operators and a huge number of functions (Left$, Right$, Mid$, Round, StartsWith, EndsWith, Contains, Upper$, Lower$, Year, Month, Day, Len, Empty, DateInRange, NumInRange, Artim$, LTrim$, RTrim$). Microsoft's SQL server can support some additional date functions like AddDays, AddWeeks and the like. If a filter uses just these supported functions, it gets automatically translated to a native database query – lightning fast!



b) Partial compatibility to database. This means, a part of an expression can be translated while another part (that is concatenated with "and") can not. In this case, the supported part is performed using native filtering whereas the unsupported part is done by the reporting engine. But it is still quite fast.



c) No compatibility to database. The filtering is performed by the reporting engine. You should try to change the filter condition to a supported syntax or do some pre-filtering beforehand.
 

For custom DataProvider classes, the required interfaces are documented and can be implemented quite easily.
If you're not working with .NET, your language needs to provide support for callbacks and you need to be able to work with VARIANTs. If these features are supported, you can quite easily write your own translation for your custom database system.




Author: Jochen Bartlau
Head of Development List & Label

Jochen Bartlau leads the development at combit as Managing Director. He's a Microsoft .NET enthusiast driving innovation & agile project management. The mobile devices geek who used to be a physicist in his first life loves to spend his spare time with his family.


  

+1 800 256 3608 (toll-free North America only)