Home » RDBMS Server » Server Administration » CLUSTER Table - Syntax
CLUSTER Table - Syntax [message #60141] Mon, 19 January 2004 00:38 Go to next message
Patrick Tahiri
Messages: 119
Registered: January 2004
Senior Member
I have some Oracle books, but none of them have info about how to create clustered tables!?

Does someone have the CREATE clustered table syntax?

My table contains a column with a relatively low cardinality (numbers between 0 - 36) and contains about 70 000 rows.

My process is that this column is compared to a number (integer) and if there is a match the entire corresponding row is then inserted into another table.

I would like to cluster all the table around this column so that all the range matching that number will be clustered on disk and inserted more quickly into the other table!

Thank you for your help.

Regards,

Patrick Tahiri.
Re: CLUSTER Table - Syntax [message #60142 is a reply to message #60141] Mon, 19 January 2004 01:15 Go to previous messageGo to next message
Frank Naude
Messages: 4580
Registered: April 1998
Senior Member
Hi,

See the "Create Cluster" command in the Oracle SQL Reference Guide. Here's an example:

SQL> -- Create the cluster...
SQL> CREATE CLUSTER emp_dept_cluster (
  2    deptno NUMBER);
Cluster created.

SQL> -- Create the cluster index...
SQL> CREATE INDEX emp_dept_cluster_index ON CLUSTER emp_dept_cluster;
Index created.

SQL> -- Create tables within the cluster...
SQL> CREATE TABLE emp (
  2    empid  NUMBER,
  3    name      VARCHAR2(30),
  4    deptno NUMBER)
  5    CLUSTER emp_dept_cluster(deptno);
Table created.
SQL> CREATE TABLE dept (
  2    deptno NUMBER,
  3    name      VARCHAR2(30))
  4    CLUSTER emp_dept_cluster(deptno);
Table created.

SQL> -- Insert test data...
SQL> INSERT INTO dept VALUES (1, 'Depta');
1 row created.
SQL> INSERT INTO emp  VALUES (1, 'Me',  1);
1 row created.
SQL> INSERT INTO emp  VALUES (2, 'You', 1);
1 row created.

SQL> -- Cluster tables share rowid's...
SQL> SELECT ROWID, empid FROM emp;
ROWID                   EMPID
------------------ ----------
AAAEDbAABAAAJZQAAA          1
AAAEDbAABAAAJZQAAB          2

SQL> SELECT ROWID, deptno FROM dept;
ROWID                  DEPTNO
------------------ ----------
AAAEDbAABAAAJZQAAA          1


Nevertheless, I'm not sure if clusters will speed-up inserts. People occasionally cluster tables to provide quicker SELECT access iff two or more tables are always joined together.

Best regards.

Frank
Re: CLUSTER Table - Syntax [message #60145 is a reply to message #60142] Mon, 19 January 2004 01:47 Go to previous messageGo to next message
Patrick Tahiri
Messages: 119
Registered: January 2004
Senior Member
Thank you very much Frank!

Regards,

Patrick Tahiri.
Re: CLUSTER Table - Syntax [message #60146 is a reply to message #60142] Mon, 19 January 2004 02:15 Go to previous messageGo to next message
Patrick Tahiri
Messages: 119
Registered: January 2004
Senior Member
Something more about this...

When one creates a cluster on a column...
After creating a table and appending one of its column to the cluster: do we have this column physically clustered on disk too like an index and ordered like an index? In ascending or descending order? Can we have redondant values on the clustered column?

Thank you in advance!

Best regards,

Patrick Tahiri.
Re: CLUSTER Table - Syntax [message #60158 is a reply to message #60146] Tue, 20 January 2004 01:08 Go to previous message
Frank Naude
Messages: 4580
Registered: April 1998
Senior Member
Hi,

The cluster index is ordered, rows in the clustered tables do not have any specific order.

The "clustered column" is stored only once for all tables within the cluster. So, you save a bit of space - not much though.

Best regards.

Frank
Previous Topic: Oracle server error
Next Topic: Endless stored procedure leaves an open session
Goto Forum:
  


Current Time: Fri Sep 20 10:39:30 CDT 2024