0

I used Oracle for the half past year and learned some tricks of sql tuning,but now our DB is moving to greenplum and the project manager suggest us to change some of the codes that writted in Oracle sql for their efficiency or grammar.

I am curious that Are sql tuning ways same for different DB engine,like oracle,postgresql,mysql and so on?if yes or not,why?Any suggestion are welcomed!

some like:

  1. in or exists
  2. count(*) or count(column)
  3. use index or not
  4. use exact column instead of select *
Robinson
  • 45
  • 1
  • 8
  • There are a lot of principles that work across databases. There are some things that are database specific. – Gordon Linoff Mar 21 '18 at 01:18
  • This is like asking, do you drive cars differently based on the purpose of the vehicle? Yeah, you drive and use a truck differently from a sports car. – Jon Roberts Mar 21 '18 at 02:16
  • https://dba.stackexchange.com/questions/201537/are-sql-tuning-ways-same-for-different-db-engine – miracle173 Mar 21 '18 at 02:36
  • One year ago you "used Oracle for the half past year", now you used Oracle for the one and a half past year. – miracle173 Mar 21 '18 at 02:44
  • `count(*)` and `count(column)` are doing two different things. –  Mar 21 '18 at 15:15

2 Answers2

2

For the most part the syntax that is used will remain the same, there may be small differences from one engine to another and you may run into different terms to achieve some of the more specific output or do more complex tasks. In order to achieve parity you will need to learn those new terms.

As far as tuning, this will vary from system to system. Specifically going from Oracle to Greenplum you are looking at moving from a database where efficiency in a query if often driven by dropping an index on the data. Where Greenplum is a parallel execution system where efficiency is gained by effectively distributing the data across multiple systems and querying them in parallel. In Greenplum indexing is an additional layer that usually does not add benefit, just additional overhead.

Even within a single system using changing the storage engine type can result in different ways to optimize a query. In practice queries are often moved to a new platform and work, but are far from optimal as they don't take advantage of optimizations of that platform. I would strongly suggest getting an understanding of the new platform and you should not go in assuming a query that is optimized for one platform is the optimal way to run it in another.

  • that's very helpful!yes,I am not looking for specific details,the overall site is good enough to follow details by myself – Robinson Mar 22 '18 at 01:29
1

Getting specifics in why they differ requires someone to be an expert in bother to be able to compare both. I don't claim to know much of greenplum.

The basic principles which I would expect all developers to learn over time dont really change. But there are "quirks" of individual engines which make specific differences. From your question I would personally anticipate 1 and 4 to remain the same.

Indexing is something which does vary. For example the ability to use two indexes was not (is not?) Ubiquitous. I wouldn't like to guess which DBMS can / can't count columns from the second field in a composite index. And the way indexes are maintained is very different from one DBMS to the next.

From my own experience I've also seen differences caused by: Different capabilities in the data access path. As an example, one optimisation is for a DBMS to create a bit map of rows (matching and not matching) the combine multiple bitmaps to select rows. A DBMS with this feature can use multiple indexes in a single query. One without it can't.

Availability of hints / lack of hints. Not all DBMS support them. I know they are very common in Oracle.

Different locking strategies. This is a big one and can really affect update and insert queries.

In some cases DBMS have very specific capabilities for certain types of data such as geographic data or searchable free text (natural language). In these cases the way of working with the data is entirely different from one DBMS to the next.

Philip Couling
  • 13,581
  • 5
  • 53
  • 85