Do not use LOB in Oracle(OLTP) -- record an optimization experience

简介:

Front knowledge

LOB in Oracle

LOB is used in Oracle to store text logger than 4000. 
We don't use Oracle in a OLTP system. 
Conside of RT and IO, we choose some other ways to provide log text. For example, CDN.

LOB in cx_Oracle

As mentioned in Some tricks when using cx_Oracle, we must convert LOB to string for each line we fetched.

  self._cursor.execute(sql, *args)
    def fix_lob(row):
        def convert(col):
            if isinstance(col, cx_Oracle.LOB):
                return str(col)
            else:
                return col

        return [convert(c) for c in row]

  return [fix_lob(r) for r in self._cursor]

But it will bring out a significant cost of CPU time in Python, which you chould see later.

Profile

I use CProfile to profile my Python code. It's very easy to use.

  import CProfile
  CProfile.run("unittest....")

This is part of my profile.

      ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      209391 1286.084  0.006 1286.559    0.006   DB.py:116(convert)
      4630   346.679   0.075  346.679    0.075   {method 'executemany' of 'cx_Oracle.Cursor' objects}
      4654   90.788    0.020   90.788    0.020   {method 'commit' of 'cx_Oracle.Connection' objects}

200k times call of convert cost 2000+ sec. Is't because Python LOB=>str is very slow. 
4k times of commit and executemany because of the lag between two servers.


目录
相关文章
|
SQL 存储 算法
《Optimization of Common Table Expressions in MPP Database Systems》论文导读
Optimization of Common Table Expressions in MPP Database Systems
《Optimization of Common Table Expressions in MPP Database Systems》论文导读
|
SQL 存储 Oracle
《Oracle Database In-Memory: A Dual Format In-Memory Database》
Oracle IMC是第一个商用的dual-format数据库。
《Oracle Database In-Memory: A Dual Format In-Memory Database》
|
SQL Oracle 算法
Cost-based query transformation in Oracle
这篇paper主要介绍了Oracle从10g开始引入的CBQT(Cost Based Query Transformation)框架。虽然以Oracle历来的风格,无法期待它在paper中讨论很多细节,不过这篇还是可以让我们一窥Oracle对于query rewrite的处理思路和很多非常实用的query rewrite模式,对于开发优化器的同学很有参考意义。 值得一提的是,PolarDB目前也在做这方面的工作,而主要的参考正是这篇paper。此外这篇paper的思路和MemSQL optimizer中对query rewrite的处理思路非常接近,关于MemSQL optimizer的介绍可
261 0
Cost-based query transformation in Oracle
|
关系型数据库