Oracle 10g small Blob or Clob not being stored inline?

前端 未结 5 986
一个人的身影
一个人的身影 2021-02-14 00:42

According to the documents I\'ve read, the default storage for a CLOB or BLOB is inline, which means that if it is less than approx 4k in size then it will be held in the table.

5条回答
  •  野的像风
    2021-02-14 01:01

    The behavior of Oracle LOBs is the following.

    A LOB is stored inline when:

    (
      The size is lower or equal than 3964
      AND
      ENABLE STORAGE IN ROW has been defined in the LOB storage clause
    ) OR (
      The value is NULL
    )
    

    A LOB is stored out-of-row when:

    (
      The value is not NULL
    ) AND (
      Its size is higher than 3964
      OR
      DISABLE STORAGE IN ROW has been defined in the LOB storage clause
    )
    

    Now this is not the only issue which may impact performance.

    If the LOBs are finally not stored inline, the default behavior of Oracle is to avoid caching them (only inline LOBs are cached in the buffer cache with the other fields of the row). To tell Oracle to also cache non inlined LOBs, the CACHE option should be used when the LOB is defined.

    The default behavior is ENABLE STORAGE IN ROW, and NOCACHE, which means small LOBs will be inlined, large LOBs will not (and will not be cached).

    Finally, there is also a performance issue at the communication protocol level. Typical Oracle clients will perform 2 additional roundtrips per LOBs to fetch them: - one to retrieve the size of the LOB and allocate memory accordingly - one to fetch the data itself (provided the LOB is small)

    These extra roundtrips are performed even if an array interface is used to retrieve the results. If you retrieve 1000 rows and your array size is large enough, you will pay for 1 roundtrip to retrieve the rows, and 2000 roundtrips to retrieve the content of the LOBs.

    Please note it does not depend on the fact the LOB is stored inline or not. They are complete different problems.

    To optimize at the protocol level, Oracle has provided a new OCI verb to fetch several LOBs in one roundtrips (OCILobArrayRead). I don't know if something similar exists with JDBC.

    Another option is to bind the LOB on client side as if it was a big RAW/VARCHAR2. This only works if a maximum size of the LOB can be defined (since the maximum size must be provided at bind time). This trick avoids the extra rountrips: the LOBs are just processed like RAW or VARCHAR2. We use it a lot in our LOB intensive applications.

    Once the number of roundtrips have been optimized, the packet size (SDU) can be resized in the net configuration to better fit the situation (i.e. a limited number of large roundtrips). It tends to reduce the "SQL*Net more data to client" and "SQL*Net more data from client" wait events.

提交回复
热议问题