Bitfiddler
Bitfiddler

Reputation: 4202

SQL string size reduction

I don't know the magic keywords to get google to answer this for me so forgive me if this is widely available knowledge.

When writing a query statement in code, the resulting string will either be difficult to read (this example is pretty simple but hopefully you get the point):

var sqlString = "Select e.f_name as FirstName, e.l_name as LastName from Employees as e where start_date > '2020-05-01'";

Or the query will be easy to read but contain a lot of extra whitespace and longer than necessary aliases:

var sqlString = 
    @"Select emp.f_name as FirstName
           , emp.l_name as LastName
      From Employees as emp
      Where start_date > '2020-05-01'";

2 questions:

Does ado.net or Oracle.ManagedDataAccess do any kind of string compression automatically to make this a non-issue for very large query expressions?

If the answer to the above is NO, then is there a library that can intelligently strip out whitespace and replace long aliases with short ones without messing up whitespace/text within query strings?

Upvotes: 0

Views: 328

Answers (1)

David Browne - Microsoft
David Browne - Microsoft

Reputation: 89361

Does ado.net or Oracle.ManagedDataAccess do any kind of string compression automatically to make this a non-issue for very large query expressions?

Fast networks mostly made this a non-issue decades ago. For most scenarios it's really not going to matter.

But ODP.NET is one of the few providers that has a client-side statement cache, which even works with connection pooling if you want. With statement caching a statement is prepared and subsequent invocations don't send the query text over the wire.

And you can always format your SQL queries to be readable, pastable, and minimize whitespace like this:

           var sqlString = @"
Select 
  emp.f_name as FirstName
  emp.l_name as LastName
From Employees as emp
Where start_date > :startDate
";

Upvotes: 2

Related Questions