question

thecoop avatar image
thecoop asked

What is a subobject?

In all_objects theres a a column called SUBOBJECT_NAME, and the docs say that this is:

Name of the subobject (for example, partition)

If you do the following query:

select * from all_types where owner = 'MDSYS' and type_name = 'SDO_TGL_OBJECT_ARRAY'

You find that MDSYS.SDO_TGL_OBJECT_ARRAY has a subobject called $VNS_1. What is it? How can types have subobjects?

oracletypesubobject
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Andrew Mobbs avatar image
Andrew Mobbs answered

I noticed the answer you got for this question over at StackOverflow, which I think is accurate. For the record here, the suggestion is that it's to do with type versioning.

I'll expand on that a bit here, hopefully to give a better understanding (and also because researching this was interesting).

Oracle objects aren't versioned, but types are, so my best guess is that Oracle used the subobject name to give a method of versioning the objects associated with the type definitions. This is sort of confirmed if you look at the data dictionary definitions in $ORACLE_HOME/rdbms/admin/catadt.sql, you'll see the %_TYPES views join between sys.type$ and sys.obj$ and have a condition of "o.subname IS NULL" and a comment "only the most recent version".

A quick experiment is interesting:

   SQL> CREATE OR REPLACE TYPE ajm_t AS OBJECT(a number, b number);
      2  /
    SQL> SELECT t.toid,t.version#,t.version,t.tvoid,o.obj#,o.name,o.subname
      2  FROM type$ t INNER JOIN obj$ o
      3  ON t.tvoid=o.oid$
      4  WHERE o.name='AJM_T';

    TOID                               VERSION# VERSION                        TVOID                                  OBJ#
    -------------------------------- ---------- ------------------------------ -------------------------------- ----------
    NAME                           SUBNAME
    ------------------------------ ------------------------------
    7E4C10976F759614E040A8C068385DCF          1 $8.0                           7E4C10976F759614E040A8C068385DCF      74708
    AJM_T

So, initially we have one type with a version name of "$8.0" (at a guess, referring to being introduced in Oracle 8.0, or the definition scheme introduced then).

SQL> ALTER TYPE ajm_t ADD ATTRIBUTE (c number);

Type altered.

SQL> SELECT t.toid,t.version#,t.version,t.tvoid,o.obj#,o.name,o.subname
  2  FROM type$ t INNER JOIN obj$ o
  3  ON t.tvoid=o.oid$
  4  WHERE o.name='AJM_T';

TOID                               VERSION# VERSION                        TVOID                                  OBJ#
-------------------------------- ---------- ------------------------------ -------------------------------- ----------
NAME                           SUBNAME
------------------------------ ------------------------------
7E4C10976F759614E040A8C068385DCF          1 $8.0                           7E4C10976F7A9614E040A8C068385DCF      74708
AJM_T                          $VSN_1

7E4C10976F759614E040A8C068385DCF          2 $VSN_2                         7E4C10976F759614E040A8C068385DCF      74709
AJM_T


SQL> ALTER TYPE ajm_t ADD ATTRIBUTE (d number);

Type altered.

SQL> SELECT t.toid,t.version#,t.version,t.tvoid,o.obj#,o.name,o.subname
  2  FROM type$ t INNER JOIN obj$ o
  3  ON t.tvoid=o.oid$
  4  WHERE o.name='AJM_T';

TOID                               VERSION# VERSION                        TVOID                                  OBJ#
-------------------------------- ---------- ------------------------------ -------------------------------- ----------
NAME                           SUBNAME
------------------------------ ------------------------------
7E4C10976F759614E040A8C068385DCF          1 $8.0                           7E4C10976F7A9614E040A8C068385DCF      74708
AJM_T                          $VSN_1

7E4C10976F759614E040A8C068385DCF          2 $VSN_2                         7E4C10976F809614E040A8C068385DCF      74709
AJM_T                          $VSN_2

7E4C10976F759614E040A8C068385DCF          3 $VSN_3                         7E4C10976F759614E040A8C068385DCF      74710
AJM_T

For the first modification, there's a bit of a weird artifact that the VERSION in type$ is "$8.0" but the subobject name given in obj$ is "$VSN_1". After the first version, things start to look more consistent. When a type is modified, a new object with a NULL subobject name is created, a new type is created and the subobject of the old object becomes the version field of the old type.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.