~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to storage/falcon/StorageTableShare.cpp

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "Sequence.h"
26
26
#include "Index.h"
27
27
#include "Table.h"
 
28
#include "Field.h"
28
29
#include "Interlock.h"
29
30
#include "CollationManager.h"
30
31
#include "MySQLCollation.h"
36
37
static const char *FALCON_TEMPORARY             = "/falcon_temporary";
37
38
static const char *DB_ROOT                              = ".fts";
38
39
 
 
40
#ifndef ONLINE_ALTER
 
41
//#define ONLINE_ALTER
 
42
#endif
 
43
 
39
44
#if defined(_WIN32) && MYSQL_VERSION_ID < 0x50100
40
45
#define IS_SLASH(c)     (c == '/' || c == '\\')
41
46
#else
59
64
        initialized = false;
60
65
        table = NULL;
61
66
        indexes = NULL;
 
67
        format = NULL;
62
68
        syncObject = new SyncObject;
63
69
        syncObject->setName("StorageTableShare::syncObject");
64
70
        sequence = NULL;
113
119
        if (!table)
114
120
                {
115
121
                table = storageDatabase->findTable(name, schemaName);
 
122
                
 
123
                if (table)
 
124
                        format = table->getCurrentFormat();
 
125
                        
116
126
                sequence = storageDatabase->findSequence(name, schemaName);
117
127
                }
118
128
        
124
134
 
125
135
int StorageTableShare::create(StorageConnection *storageConnection, const char* sql, int64 autoIncrementValue)
126
136
{
127
 
        if (!(table = storageDatabase->createTable(storageConnection, name, schemaName, sql, autoIncrementValue)))
128
 
                return StorageErrorTableExits;
 
137
        try
 
138
                {
 
139
                table = storageDatabase->createTable(storageConnection, name, schemaName, sql, autoIncrementValue);
 
140
                }
 
141
        catch (SQLException& exception)
 
142
                {
 
143
                int sqlcode= exception.getSqlcode();
 
144
                switch (sqlcode)
 
145
                        {
 
146
                        case TABLESPACE_NOT_EXIST_ERROR:
 
147
                                return StorageErrorTableSpaceNotExist;
 
148
                        default:
 
149
                                return StorageErrorTableExits;
 
150
                        }
 
151
                }
 
152
        if (!table)
 
153
                return StorageErrorTableExits;
 
154
        
 
155
        format = table->getCurrentFormat();
 
156
 
 
157
        if (autoIncrementValue)
 
158
                sequence = storageDatabase->findSequence(name, schemaName);
 
159
                
 
160
        return 0;
 
161
}
 
162
 
 
163
int StorageTableShare::upgrade(StorageConnection *storageConnection, const char* sql, int64 autoIncrementValue)
 
164
{
 
165
        if (!(table = storageDatabase->upgradeTable(storageConnection, name, schemaName, sql, autoIncrementValue)))
 
166
                return StorageErrorTableExits;
 
167
 
 
168
        format = table->getCurrentFormat();
129
169
        
130
170
        if (autoIncrementValue)
131
171
                sequence = storageDatabase->findSequence(name, schemaName);
141
181
                {
142
182
                unRegisterTable();
143
183
                
144
 
                if (res == 0)
145
 
                        storageHandler->removeTable(this);
 
184
                storageHandler->removeTable(this);
146
185
                        
147
186
                delete this;
148
187
                }
215
254
        return storageDatabase->createIndex(storageConnection, table, name, sql);
216
255
}
217
256
 
 
257
int StorageTableShare::dropIndex(StorageConnection *storageConnection, const char* name, const char* sql)
 
258
{
 
259
        if (!table)
 
260
                open();
 
261
 
 
262
        return storageDatabase->dropIndex(storageConnection, table, name, sql);
 
263
}
 
264
 
218
265
int StorageTableShare::renameTable(StorageConnection *storageConnection, const char* newName)
219
266
{
220
267
        char tableName[256];
236
283
 
237
284
StorageIndexDesc* StorageTableShare::getIndex(int indexCount, int indexId, StorageIndexDesc* indexDesc)
238
285
{
 
286
        // Rebuild array if indexes have been added or dropped
 
287
        
 
288
#ifdef ONLINE_ALTER
 
289
 
 
290
        // TODO: This does not work. It should be done at the time of index creation
 
291
 
 
292
        if (indexes && (numberIndexes != indexCount))
 
293
                {
 
294
                Sync sync(syncObject, "StorageTableShare::getIndex");
 
295
                sync.lock(Exclusive);
 
296
                StorageIndexDesc **oldIndexes = indexes;
 
297
                StorageIndexDesc **newIndexes = new StorageIndexDesc*[indexCount];
 
298
                memset(newIndexes, 0, indexCount * sizeof(StorageIndexDesc*));
 
299
                
 
300
                for (int n = 0; n < numberIndexes; ++n)
 
301
                        newIndexes[n] = indexes[n];
 
302
                
 
303
                indexes = newIndexes;
 
304
                numberIndexes = indexCount;
 
305
                delete [] oldIndexes;
 
306
                }
 
307
#endif
 
308
        
239
309
        if (!indexes)
240
310
                {
241
311
                indexes = new StorageIndexDesc*[indexCount];
317
387
        return -1;
318
388
}
319
389
 
320
 
int StorageTableShare::haveIndexes(void)
 
390
int StorageTableShare::haveIndexes(int indexCount)
321
391
{
322
392
        if (indexes == NULL)
323
393
                return false;
 
394
                
 
395
#ifdef ONLINE_ALTER
 
396
        if (indexCount != numberIndexes)
 
397
                return false;
 
398
#endif  
324
399
        
325
400
        for (int n = 0; n < numberIndexes; ++n)
326
401
                if (indexes[n]== NULL)
545
620
//              syncTruncate->unlock(NULL, Shared);
546
621
                }
547
622
}
 
623
 
 
624
int StorageTableShare::getFieldId(const char* fieldName)
 
625
{
 
626
        Field *field = table->findField(fieldName);
 
627
        
 
628
        if (!field)
 
629
                return -1;
 
630
        
 
631
        return field->id;
 
632
}