Project

General

Profile

« Previous | Next » 

Revision 2710

Added by sgarg over 18 years ago

Faster script for upgrading oracle database

View differences:

upgrade-db-to-1.6.sql
136 136
/**
137 137
 * Delete the records from xml_nodes which were transfered to xml_nodes_revisions 
138 138
 */
139
DELETE FROM xml_nodes WHERE rootnodeid NOT IN
140
(SELECT rootnodeid from xml_documents where rootnodeid is not NULL);
139

  
140
/**
141
 * Below given statement takes a lot of time to excute
142
 *
143
 * DELETE FROM xml_nodes WHERE rootnodeid NOT IN
144
 * (SELECT rootnodeid from xml_documents where rootnodeid is not NULL);
145
 *
146
 * Hence.....
147
 */
148

  
149

  
150
/**
151
* Drop the xml_nodes primark key....
152
*/
153
ALTER TABLE xml_nodes DROP CONSTRAINT xml_nodes_pk CASCADE;
154

  
155

  
156
/** rename xml_nodes to xml_nodes_2 */
157
ALTER TABLE xml_nodes RENAME TO xml_nodes_2;
158

  
159
/** create a new xml_nodes table with new primary and foreign keys*/
160
CREATE TABLE xml_nodes (
161
       nodeid          NUMBER(20),     -- the unique node id (pk)
162
       nodeindex       NUMBER(10),     -- order of nodes within parent
163
       nodetype        VARCHAR2(20),   -- type (DOCUMENT, COMMENT, PI,
164
                                       -- ELEMENT, ATTRIBUTE, TEXT)
165
       nodename        VARCHAR2(250),  -- the name of an element or attribute
166
       nodeprefix      VARCHAR2(50),   -- the namespace prefix of an element
167
                                       -- or attribute
168
       nodedata        VARCHAR2(4000), -- the data for this node (e.g.,
169
                                       -- for TEXT it is the content)
170
       parentnodeid    NUMBER(20),     -- index of the parent of this node
171
       rootnodeid      NUMBER(20),     -- index of the root node of this tree
172
       docid           VARCHAR2(250),  -- index to the document id
173
       date_created    DATE,
174
       date_updated    DATE,
175
       nodedatanumerical NUMBER,       -- the data for this node if
176
                                       -- it is a number
177
  CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
178
  CONSTRAINT xml_nodes_root_fk
179
               FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
180
  CONSTRAINT xml_nodes_parent_fk
181
               FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
182
);
183

  
184
/** copy nodes from xml_nodes_2  to xml_nodes */
185
INSERT INTO xml_nodes (nodeid, nodeindex, nodetype, nodename, nodeprefix, nodedata, parentnodeid, rootnodeid, docid, date_created, date_updated, nodedatanumerical) SELECT n.nodeid, n.nodeindex, n.nodetype, n.nodename, n.nodeprefix, n.nodedata, n.parentnodeid, n.rootnodeid, n.docid, n.date_created, n.date_updated, n.nodedatanumerical FROM xml_nodes_2 n, xml_nodes_revisions r WHERE n.rootnodeid = r.rootnodeid(+) AND r.rootnodeid is NULL;
186

  
187

  
188
/** Drop old indexes **/
189
DROP INDEX xml_nodes_idx1;
190
DROP INDEX xml_nodes_idx2;
191
DROP INDEX xml_nodes_idx3;
192

  
193
/** Create new indexes **/
194
CREATE INDEX xml_nodes_idx1 ON xml_nodes (rootnodeid);
195
CREATE INDEX xml_nodes_idx2 ON xml_nodes (parentnodeid);
196
CREATE INDEX xml_nodes_idx3 ON xml_nodes (nodename);
197

  
198
/** Add constaints which were deleted before moving xml_nodes to xml_nodes_2 */
199
ALTER TABLE xml_documents ADD CONSTRAINT xml_documents_root_fk FOREIGN KEY (rootnodeid) REFERENCES xml_nodes;
200
ALTER TABLE xml_index ADD CONSTRAINT xml_index_nodeid_fk FOREIGN KEY (nodeid) REFERENCES xml_nodes;
201

  
202
/** Drop xml_nodes_2 table */
203
DROP TABLE xml_nodes_2;
204

  
205
/** Done */
206

  
207

  

Also available in: Unified diff