27-Jul-2011: Strings in Oracle RDBMS network layer

Not sure if it's worth blogging...

All strings in Oracle RDBMS network layer are usual C-strings terminated by zero byte, but often, string length is also passing as a separate function argument. This makes some things much faster.

Instead of:

if (strcmp (s, "STRING")) ...

We have (we first check 's' string len against "STRING" length, if it doesn't equal, we may not compare each byte):

if (s_len==6)
    if (strcmp (s, "STRING"))..

Another example is:

if (strcmp (s, "ASD"))...
if (strcmp (s, "DEF"))...

if (strcmp (s, "ASD1"))...
if (strcmp (s, "ORCL"))...

Instead, we can write:

void f(char* s, int s_len)
{

if (s_len==3)
{
... check s against all 3-char strings here: ASD, DEF
}
else
if (s_len==4)
{
... check s against all 4-char strings here: ASD1, ORCL
}
else
{
... check the rest
}

... which is much faster, of course.

All strings are still C-strings with zero byte at the end, so they are all can be used as argument to any C standard library function.


This open sourced site and this page in particular is hosted on GitHub. Patches, suggestions and comments are welcome.


→ [list of blog posts, my twitter/facebook]

The page last updated on 26-April-2016