Enhancing PostgreSQL performance tuning capabilities

One of the greatest features of Postgres is extensibility. In particular, extensions can help to dramatically improve performance troubleshooting capabilities. You can leverage built-in extensions or install from some third-party repositories managed by companies like Percona or EDB or simply install them from git sources.

One of the typical performance issues is when some process takes much longer than it used to take in the past. This post describes Top 5 extensions which can help with such retrospective analysis.

Continue reading “Enhancing PostgreSQL performance tuning capabilities”

Varattrs tables in Oracle

A lot of programming languages allow to declare functions which accept arbitrary number of attributes and such functions are often referred as varargs functions. Even Oracle has such functions – for example, SQL function decode or PL/SQL function utl_lms.format_message. Unfortunately, Oracle does not allow to declare user defined varargs functions but this post is not about that.

From time to time Data Architects have to deal with the challenge to store entities with arbitrary attributes. If all possible entities are not known in advance during the schema design then it’s not possible to create a table with all the necessary attributes. Possible solutions in such cases are

  • EAV design + pivot
  • Storing entities in XML/JSON format or simply as varchar (latter would require implementing the logic for parsing)

Above solutions are not even close from performance perspective to the design when we can create a table with all needed attributes in advance. Nevertheless there is a solution with very similar performance.
Continue reading “Varattrs tables in Oracle”

Group by an expression… and limitations of MDX vs SQL

Some queries can be easily expressed with MDX while it’s not possible to get the same result using SQL. For example, if we use Adventure Works sample cube and would like to display internet gross profits by country in a way so that we have separate column for each year it can be easily achieved with below MDX.

select
  non empty [Date].[Calendar Year].[Calendar Year] on 0,
  [Customer].[Country].[Country] * [Measures].[Internet Gross Profit] on 1
from [Adventure Works]

It displays column for each year which has data for internet gross profits. In SQL, however, all columns must be explicitly listed in a query (or derived from table structure in case of select *) – whether in select list or in pivot clause. Generically speaking, SQL is designed to return two-dimensional datasets with arbitrary number of rows and pre-defined number of columns while MDX can return data on multiple axes (dimensions) although it’s a tricky question how to visualize the output if we use more than 2 axes.

On the other hand, sometimes it quite challenging to implement the logic in MDX which can be expressed using SQL in a very trivial manner. Let’s consider a couple of cases.
Continue reading “Group by an expression… and limitations of MDX vs SQL”

Domain indexes. Built-in vs DIY.

In this I’ll do a quick performance comparison of built-in Oracle Text index versus the one created using Extensible indexing interface (described in this post).

First of all, Oracle Text option must be installed to use built-in text indexes. This functionality is getting installed under CTXSYS schema.

Speaking about DIY text indexes, it’s mandatory to have privileges to create index types and operators or simply RESOURCE role.

Continue reading “Domain indexes. Built-in vs DIY.”

Scala external procedures in Oracle

I assume it would be more correct to say “using scala functions in Oracle” but Oracle documentation uses terms like External Procedures or External Subprograms.

There are no specific details about scala with regard to external procedures in Oracle but given that scala code is translated into Java byte code there should be no difficulties in using scala as a language for stored code as well.

Of course, there is no scala compiler in Oracle so we cannot run statement like create or replace and compile java source but we can compile scala code in advance and upload classes using loadjava utility.

All java methods which are mapped to PL/SQL routines must be static and since there are no static methods in scala the typical approach to mimic them is by declaring functions in an object rather than in a class.
Continue reading “Scala external procedures in Oracle”