Merge lp:~vkolesnikov/pbxt/pbxt-bug-378222 into lp:pbxt

Proposed by Vladimir Kolesnikov
Status: Merged
Merged at revision: not available
Proposed branch: lp:~vkolesnikov/pbxt/pbxt-bug-378222
Merge into: lp:pbxt
Diff against target: None lines
To merge this branch: bzr merge lp:~vkolesnikov/pbxt/pbxt-bug-378222
Reviewer Review Type Date Requested Status
PBXT Core Pending
Review via email: mp+7376@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Paul McCullagh (paul-mccullagh) wrote :

Hi Vlad,

This patch looks good. Just one thing: how about doing this in
xt_tab_init_db()?

I think this would be more efficient.

On Jun 12, 2009, at 4:40 PM, Vladimir Kolesnikov wrote:

> === modified file 'src/database_xt.cc'
> --- src/database_xt.cc 2009-05-28 15:17:16 +0000
> +++ src/database_xt.cc 2009-06-12 14:29:30 +0000
> @@ -616,7 +616,9 @@
> xtPublic void xt_open_database(XTThreadPtr self, char *path, xtBool
> multi_path)
> {
> XTDatabaseHPtr db;
> -
> + XTTableDescRec desc;
> + XTPathStr table_path;
> +
> /* We cannot get a database, without unusing the current
> * first. The reason is that the restart process will
> * partially set the current database!
> @@ -625,7 +627,18 @@
> db = xt_get_database(self, path, multi_path);
> pushr_(xt_heap_release, db);
> xt_use_database(self, db, XT_FOR_USER);
> - freer_(); // xt_heap_release(self, db);
> +
> + xt_describe_tables_init(self, db, &desc);
> + pushr_(xt_describe_tables_exit, &desc);
> + while (xt_describe_tables_next(self, &desc)) {
> + xt_strcpy(PATH_MAX, table_path.ps_path, desc.td_tab_path->tp_path);
> + xt_add_dir_char(PATH_MAX, table_path.ps_path);
> + xt_strcat(PATH_MAX, table_path.ps_path, desc.td_tab_name);
> + xt_heap_release(self, xt_use_table(self, &table_path, FALSE,
> FALSE, NULL));
> + }
> +
> + freer_(); // xt_describe_tables_exit(self, desc);
> + freer_(); // xt_heap_release(self, db);
> }
>

--
Paul McCullagh
PrimeBase Technologies
www.primebase.org
www.blobstreaming.org
pbxt.blogspot.com

Revision history for this message
Vladimir Kolesnikov (vkolesnikov) wrote :

This was my first idea too, but xt_use_table requires self->st_database
to be inited which is done in xt_ue_database() so I put this code right
after the call to xt_use_database (and xt_use_database itself doesn't
seem to be good place too). Of course I can copy some code from
xt_use_database and put it before the use_table but I thought it's not a
good idea.

Paul McCullagh wrote:
> Hi Vlad,
>
> This patch looks good. Just one thing: how about doing this in
> xt_tab_init_db()?
>
> I think this would be more efficient.
>
> On Jun 12, 2009, at 4:40 PM, Vladimir Kolesnikov wrote:
>
>
>> === modified file 'src/database_xt.cc'
>> --- src/database_xt.cc 2009-05-28 15:17:16 +0000
>> +++ src/database_xt.cc 2009-06-12 14:29:30 +0000
>> @@ -616,7 +616,9 @@
>> xtPublic void xt_open_database(XTThreadPtr self, char *path, xtBool
>> multi_path)
>> {
>> XTDatabaseHPtr db;
>> -
>> + XTTableDescRec desc;
>> + XTPathStr table_path;
>> +
>> /* We cannot get a database, without unusing the current
>> * first. The reason is that the restart process will
>> * partially set the current database!
>> @@ -625,7 +627,18 @@
>> db = xt_get_database(self, path, multi_path);
>> pushr_(xt_heap_release, db);
>> xt_use_database(self, db, XT_FOR_USER);
>> - freer_(); // xt_heap_release(self, db);
>> +
>> + xt_describe_tables_init(self, db, &desc);
>> + pushr_(xt_describe_tables_exit, &desc);
>> + while (xt_describe_tables_next(self, &desc)) {
>> + xt_strcpy(PATH_MAX, table_path.ps_path, desc.td_tab_path->tp_path);
>> + xt_add_dir_char(PATH_MAX, table_path.ps_path);
>> + xt_strcat(PATH_MAX, table_path.ps_path, desc.td_tab_name);
>> + xt_heap_release(self, xt_use_table(self, &table_path, FALSE,
>> FALSE, NULL));
>> + }
>> +
>> + freer_(); // xt_describe_tables_exit(self, desc);
>> + freer_(); // xt_heap_release(self, db);
>> }
>>
>>
>
>
>
> --
> Paul McCullagh
> PrimeBase Technologies
> www.primebase.org
> www.blobstreaming.org
> pbxt.blogspot.com
>
>
>
>

--
--
Best Regards,
Vladimir

Revision history for this message
Paul McCullagh (paul-mccullagh) wrote :

I think you could try: xt_use_table_no_lock()

Because lock on db->db_tables is not required anyway.

On Jun 16, 2009, at 12:18 PM, Vladimir Kolesnikov wrote:

> This was my first idea too, but xt_use_table requires self-
> >st_database
> to be inited which is done in xt_ue_database() so I put this code
> right
> after the call to xt_use_database (and xt_use_database itself doesn't
> seem to be good place too). Of course I can copy some code from
> xt_use_database and put it before the use_table but I thought it's
> not a
> good idea.
>
> Paul McCullagh wrote:
>> Hi Vlad,
>>
>> This patch looks good. Just one thing: how about doing this in
>> xt_tab_init_db()?
>>
>> I think this would be more efficient.
>>
>> On Jun 12, 2009, at 4:40 PM, Vladimir Kolesnikov wrote:
>>
>>
>>> === modified file 'src/database_xt.cc'
>>> --- src/database_xt.cc 2009-05-28 15:17:16 +0000
>>> +++ src/database_xt.cc 2009-06-12 14:29:30 +0000
>>> @@ -616,7 +616,9 @@
>>> xtPublic void xt_open_database(XTThreadPtr self, char *path, xtBool
>>> multi_path)
>>> {
>>> XTDatabaseHPtr db;
>>> -
>>> + XTTableDescRec desc;
>>> + XTPathStr table_path;
>>> +
>>> /* We cannot get a database, without unusing the current
>>> * first. The reason is that the restart process will
>>> * partially set the current database!
>>> @@ -625,7 +627,18 @@
>>> db = xt_get_database(self, path, multi_path);
>>> pushr_(xt_heap_release, db);
>>> xt_use_database(self, db, XT_FOR_USER);
>>> - freer_(); // xt_heap_release(self, db);
>>> +
>>> + xt_describe_tables_init(self, db, &desc);
>>> + pushr_(xt_describe_tables_exit, &desc);
>>> + while (xt_describe_tables_next(self, &desc)) {
>>> + xt_strcpy(PATH_MAX, table_path.ps_path, desc.td_tab_path-
>>> >tp_path);
>>> + xt_add_dir_char(PATH_MAX, table_path.ps_path);
>>> + xt_strcat(PATH_MAX, table_path.ps_path, desc.td_tab_name);
>>> + xt_heap_release(self, xt_use_table(self, &table_path, FALSE,
>>> FALSE, NULL));
>>> + }
>>> +
>>> + freer_(); // xt_describe_tables_exit(self, desc);
>>> + freer_(); // xt_heap_release(self, db);
>>> }
>>>
>>>
>>
>>
>>
>> --
>> Paul McCullagh
>> PrimeBase Technologies
>> www.primebase.org
>> www.blobstreaming.org
>> pbxt.blogspot.com
>>
>>
>>
>>
>
>
> --
> --
> Best Regards,
> Vladimir
>
> https://code.launchpad.net/~vkolesnikov/pbxt/pbxt-bug-378222/+merge/
> 7376
> Your team PBXT Core is subscribed to branch lp:pbxt.

--
Paul McCullagh
PrimeBase Technologies
www.primebase.org
www.blobstreaming.org
pbxt.blogspot.com

Revision history for this message
Vladimir Kolesnikov (vkolesnikov) wrote :

pushed the change

Paul McCullagh wrote:
> I think you could try: xt_use_table_no_lock()
>
> Because lock on db->db_tables is not required anyway.
>
> On Jun 16, 2009, at 12:18 PM, Vladimir Kolesnikov wrote:
>
>
>> This was my first idea too, but xt_use_table requires self-
>>
>>> st_database
>>>
>> to be inited which is done in xt_ue_database() so I put this code
>> right
>> after the call to xt_use_database (and xt_use_database itself doesn't
>> seem to be good place too). Of course I can copy some code from
>> xt_use_database and put it before the use_table but I thought it's
>> not a
>> good idea.
>>
>> Paul McCullagh wrote:
>>
>>> Hi Vlad,
>>>
>>> This patch looks good. Just one thing: how about doing this in
>>> xt_tab_init_db()?
>>>
>>> I think this would be more efficient.
>>>
>>> On Jun 12, 2009, at 4:40 PM, Vladimir Kolesnikov wrote:
>>>
>>>
>>>
>>>> === modified file 'src/database_xt.cc'
>>>> --- src/database_xt.cc 2009-05-28 15:17:16 +0000
>>>> +++ src/database_xt.cc 2009-06-12 14:29:30 +0000
>>>> @@ -616,7 +616,9 @@
>>>> xtPublic void xt_open_database(XTThreadPtr self, char *path, xtBool
>>>> multi_path)
>>>> {
>>>> XTDatabaseHPtr db;
>>>> -
>>>> + XTTableDescRec desc;
>>>> + XTPathStr table_path;
>>>> +
>>>> /* We cannot get a database, without unusing the current
>>>> * first. The reason is that the restart process will
>>>> * partially set the current database!
>>>> @@ -625,7 +627,18 @@
>>>> db = xt_get_database(self, path, multi_path);
>>>> pushr_(xt_heap_release, db);
>>>> xt_use_database(self, db, XT_FOR_USER);
>>>> - freer_(); // xt_heap_release(self, db);
>>>> +
>>>> + xt_describe_tables_init(self, db, &desc);
>>>> + pushr_(xt_describe_tables_exit, &desc);
>>>> + while (xt_describe_tables_next(self, &desc)) {
>>>> + xt_strcpy(PATH_MAX, table_path.ps_path, desc.td_tab_path-
>>>>
>>>>> tp_path);
>>>>>
>>>> + xt_add_dir_char(PATH_MAX, table_path.ps_path);
>>>> + xt_strcat(PATH_MAX, table_path.ps_path, desc.td_tab_name);
>>>> + xt_heap_release(self, xt_use_table(self, &table_path, FALSE,
>>>> FALSE, NULL));
>>>> + }
>>>> +
>>>> + freer_(); // xt_describe_tables_exit(self, desc);
>>>> + freer_(); // xt_heap_release(self, db);
>>>> }
>>>>
>>>>
>>>>
>>>
>>> --
>>> Paul McCullagh
>>> PrimeBase Technologies
>>> www.primebase.org
>>> www.blobstreaming.org
>>> pbxt.blogspot.com
>>>
>>>
>>>
>>>
>>>
>> --
>> --
>> Best Regards,
>> Vladimir
>>
>> https://code.launchpad.net/~vkolesnikov/pbxt/pbxt-bug-378222/+merge/
>> 7376
>> Your team PBXT Core is subscribed to branch lp:pbxt.
>>
>
>
>
> --
> Paul McCullagh
> PrimeBase Technologies
> www.primebase.org
> www.blobstreaming.org
> pbxt.blogspot.com
>
>
>
>

--
--
Best Regards,
Vladimir

lp:~vkolesnikov/pbxt/pbxt-bug-378222 updated
658. By Paul McCullagh

Merged RN246

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2009-06-10 16:26:33 +0000
+++ ChangeLog 2009-06-12 14:29:30 +0000
@@ -3,6 +3,8 @@
33
4------- 1.0.08 RC - Not yet released4------- 1.0.08 RC - Not yet released
55
6RN246: Fixed bug #378222: Drop sakila causes error: Cannot delete or update a parent row: a foreign key constraint fails
7
6RN245: Fixed bug #379315: Inconsistent behavior of DELETE IGNORE and FK constraint8RN245: Fixed bug #379315: Inconsistent behavior of DELETE IGNORE and FK constraint
79
8RN244: Fixed a recovery problem: during the recovery of "record modified" action the table was updated before the old index entries were removed; then the xres_remove_index_entries was supplied the new record which lead to incorrect index update10RN244: Fixed a recovery problem: during the recovery of "record modified" action the table was updated before the old index entries were removed; then the xres_remove_index_entries was supplied the new record which lead to incorrect index update
911
=== modified file 'src/database_xt.cc'
--- src/database_xt.cc 2009-05-28 15:17:16 +0000
+++ src/database_xt.cc 2009-06-12 14:29:30 +0000
@@ -616,7 +616,9 @@
616xtPublic void xt_open_database(XTThreadPtr self, char *path, xtBool multi_path)616xtPublic void xt_open_database(XTThreadPtr self, char *path, xtBool multi_path)
617{617{
618 XTDatabaseHPtr db;618 XTDatabaseHPtr db;
619 619 XTTableDescRec desc;
620 XTPathStr table_path;
621
620 /* We cannot get a database, without unusing the current622 /* We cannot get a database, without unusing the current
621 * first. The reason is that the restart process will623 * first. The reason is that the restart process will
622 * partially set the current database!624 * partially set the current database!
@@ -625,7 +627,18 @@
625 db = xt_get_database(self, path, multi_path);627 db = xt_get_database(self, path, multi_path);
626 pushr_(xt_heap_release, db);628 pushr_(xt_heap_release, db);
627 xt_use_database(self, db, XT_FOR_USER);629 xt_use_database(self, db, XT_FOR_USER);
628 freer_(); // xt_heap_release(self, db); 630
631 xt_describe_tables_init(self, db, &desc);
632 pushr_(xt_describe_tables_exit, &desc);
633 while (xt_describe_tables_next(self, &desc)) {
634 xt_strcpy(PATH_MAX, table_path.ps_path, desc.td_tab_path->tp_path);
635 xt_add_dir_char(PATH_MAX, table_path.ps_path);
636 xt_strcat(PATH_MAX, table_path.ps_path, desc.td_tab_name);
637 xt_heap_release(self, xt_use_table(self, &table_path, FALSE, FALSE, NULL));
638 }
639
640 freer_(); // xt_describe_tables_exit(self, desc);
641 freer_(); // xt_heap_release(self, db);
629}642}
630643
631/* This function can only be called if you do not already have a database in644/* This function can only be called if you do not already have a database in
632645
=== modified file 'src/datadic_xt.cc'
--- src/datadic_xt.cc 2009-05-19 15:22:26 +0000
+++ src/datadic_xt.cc 2009-06-12 14:29:30 +0000
@@ -650,7 +650,7 @@
650 int parseKeyAction(XTThreadPtr self); 650 int parseKeyAction(XTThreadPtr self);
651 void parseCreateTable(XTThreadPtr self);651 void parseCreateTable(XTThreadPtr self);
652 void parseAddTableItem(XTThreadPtr self);652 void parseAddTableItem(XTThreadPtr self);
653 void parseQualifiedName(XTThreadPtr self, char *name);653 void parseQualifiedName(XTThreadPtr self, char *parent_name, char *name);
654 void parseTableName(XTThreadPtr self, bool alterTable);654 void parseTableName(XTThreadPtr self, bool alterTable);
655 void parseExpression(XTThreadPtr self, bool allow_reserved);655 void parseExpression(XTThreadPtr self, bool allow_reserved);
656 void parseBrackets(XTThreadPtr self);656 void parseBrackets(XTThreadPtr self);
@@ -720,7 +720,7 @@
720 }720 }
721 virtual void addListedColumn(XTThreadPtr XT_UNUSED(self), char *XT_UNUSED(index_col_name)) {721 virtual void addListedColumn(XTThreadPtr XT_UNUSED(self), char *XT_UNUSED(index_col_name)) {
722 }722 }
723 virtual void setReferencedTable(XTThreadPtr XT_UNUSED(self), char *XT_UNUSED(ref_table)) {723 virtual void setReferencedTable(XTThreadPtr XT_UNUSED(self), char *XT_UNUSED(ref_schema), char *XT_UNUSED(ref_table)) {
724 }724 }
725 virtual void addReferencedColumn(XTThreadPtr XT_UNUSED(self), char *XT_UNUSED(index_col_name)) {725 virtual void addReferencedColumn(XTThreadPtr XT_UNUSED(self), char *XT_UNUSED(index_col_name)) {
726 }726 }
@@ -870,7 +870,7 @@
870 if (pt_current->isKeyWord("CONSTRAINT")) {870 if (pt_current->isKeyWord("CONSTRAINT")) {
871 pt_current = pt_tokenizer->nextToken(self);871 pt_current = pt_tokenizer->nextToken(self);
872 if (pt_current->isIdentifier())872 if (pt_current->isIdentifier())
873 parseQualifiedName(self, name);873 parseQualifiedName(self, NULL, name);
874 }874 }
875875
876 if (pt_current->isReservedWord(XT_TK_PRIMARY)) {876 if (pt_current->isReservedWord(XT_TK_PRIMARY)) {
@@ -985,13 +985,15 @@
985 char name[XT_IDENTIFIER_NAME_SIZE];985 char name[XT_IDENTIFIER_NAME_SIZE];
986986
987 pt_current = pt_tokenizer->nextToken(self);987 pt_current = pt_tokenizer->nextToken(self);
988 parseQualifiedName(self, name);988 parseQualifiedName(self, NULL, name);
989 moveColumn(self, name);989 moveColumn(self, name);
990 }990 }
991}991}
992992
993void XTParseTable::parseQualifiedName(XTThreadPtr self, char *name)993void XTParseTable::parseQualifiedName(XTThreadPtr self, char *parent_name, char *name)
994{994{
995 if (parent_name)
996 parent_name[0] = '\0';
995 /* Should be an identifier by I have this example:997 /* Should be an identifier by I have this example:
996 * CREATE TABLE t1 ( comment CHAR(32) ASCII NOT NULL, koi8_ru_f CHAR(32) CHARACTER SET koi8r NOT NULL default '' ) CHARSET=latin5;998 * CREATE TABLE t1 ( comment CHAR(32) ASCII NOT NULL, koi8_ru_f CHAR(32) CHARACTER SET koi8r NOT NULL default '' ) CHARSET=latin5;
997 *999 *
@@ -1001,6 +1003,8 @@
1001 raiseError(self, pt_current, XT_ERR_ID_TOO_LONG);1003 raiseError(self, pt_current, XT_ERR_ID_TOO_LONG);
1002 pt_current = pt_tokenizer->nextToken(self);1004 pt_current = pt_tokenizer->nextToken(self);
1003 while (pt_current->isKeyWord(".")) {1005 while (pt_current->isKeyWord(".")) {
1006 if (parent_name)
1007 xt_strcpy(XT_IDENTIFIER_NAME_SIZE,parent_name, name);
1004 pt_current = pt_tokenizer->nextToken(self);1008 pt_current = pt_tokenizer->nextToken(self);
1005 /* Accept anything after the DOT! */1009 /* Accept anything after the DOT! */
1006 if (pt_current->getString(name, XT_IDENTIFIER_NAME_SIZE) >= XT_IDENTIFIER_NAME_SIZE)1010 if (pt_current->getString(name, XT_IDENTIFIER_NAME_SIZE) >= XT_IDENTIFIER_NAME_SIZE)
@@ -1013,7 +1017,7 @@
1013{1017{
1014 char name[XT_IDENTIFIER_NAME_SIZE];1018 char name[XT_IDENTIFIER_NAME_SIZE];
10151019
1016 parseQualifiedName(self, name);1020 parseQualifiedName(self, NULL, name);
1017 setTableName(self, name, alterTable);1021 setTableName(self, name, alterTable);
1018}1022}
10191023
@@ -1022,7 +1026,7 @@
1022 char col_name[XT_IDENTIFIER_NAME_SIZE];1026 char col_name[XT_IDENTIFIER_NAME_SIZE];
10231027
1024 // column_definition1028 // column_definition
1025 parseQualifiedName(self, col_name);1029 parseQualifiedName(self, NULL, col_name);
1026 addColumn(self, col_name, old_col_name);1030 addColumn(self, col_name, old_col_name);
1027 parseDataType(self);1031 parseDataType(self);
10281032
@@ -1122,7 +1126,7 @@
1122 pt_current->expectKeyWord(self, "(");1126 pt_current->expectKeyWord(self, "(");
1123 do {1127 do {
1124 pt_current = pt_tokenizer->nextToken(self);1128 pt_current = pt_tokenizer->nextToken(self);
1125 parseQualifiedName(self, name);1129 parseQualifiedName(self, NULL, name);
1126 addListedColumn(self, name);1130 addListedColumn(self, name);
1127 cols++;1131 cols++;
1128 if (index_cols) {1132 if (index_cols) {
@@ -1146,19 +1150,20 @@
1146 int on_delete = XT_KEY_ACTION_DEFAULT;1150 int on_delete = XT_KEY_ACTION_DEFAULT;
1147 int on_update = XT_KEY_ACTION_DEFAULT;1151 int on_update = XT_KEY_ACTION_DEFAULT;
1148 char name[XT_IDENTIFIER_NAME_SIZE];1152 char name[XT_IDENTIFIER_NAME_SIZE];
1153 char parent_name[XT_IDENTIFIER_NAME_SIZE];
1149 u_int cols = 0;1154 u_int cols = 0;
11501155
1151 // REFERENCES tbl_name1156 // REFERENCES tbl_name
1152 pt_current = pt_tokenizer->nextToken(self, "REFERENCES", pt_current);1157 pt_current = pt_tokenizer->nextToken(self, "REFERENCES", pt_current);
1153 parseQualifiedName(self, name);1158 parseQualifiedName(self, parent_name, name);
1154 setReferencedTable(self, name);1159 setReferencedTable(self, parent_name[0] ? parent_name : NULL, name);
11551160
1156 // [ (index_col_name,...) ]1161 // [ (index_col_name,...) ]
1157 if (pt_current->isKeyWord("(")) {1162 if (pt_current->isKeyWord("(")) {
1158 pt_current->expectKeyWord(self, "(");1163 pt_current->expectKeyWord(self, "(");
1159 do {1164 do {
1160 pt_current = pt_tokenizer->nextToken(self);1165 pt_current = pt_tokenizer->nextToken(self);
1161 parseQualifiedName(self, name);1166 parseQualifiedName(self, NULL, name);
1162 addReferencedColumn(self, name);1167 addReferencedColumn(self, name);
1163 cols++;1168 cols++;
1164 if (cols > req_cols)1169 if (cols > req_cols)
@@ -1230,7 +1235,7 @@
1230 if (pt_current->isReservedWord(XT_TK_COLUMN))1235 if (pt_current->isReservedWord(XT_TK_COLUMN))
1231 pt_current = pt_tokenizer->nextToken(self);1236 pt_current = pt_tokenizer->nextToken(self);
12321237
1233 parseQualifiedName(self, old_col_name);1238 parseQualifiedName(self, NULL, old_col_name);
1234 parseColumnDefinition(self, old_col_name);1239 parseColumnDefinition(self, old_col_name);
1235 parseMoveColumn(self);1240 parseMoveColumn(self);
1236 }1241 }
@@ -1262,7 +1267,7 @@
1262 else {1267 else {
1263 if (pt_current->isReservedWord(XT_TK_COLUMN))1268 if (pt_current->isReservedWord(XT_TK_COLUMN))
1264 pt_current = pt_tokenizer->nextToken(self);1269 pt_current = pt_tokenizer->nextToken(self);
1265 parseQualifiedName(self, name);1270 parseQualifiedName(self, NULL, name);
1266 dropColumn(self, name);1271 dropColumn(self, name);
1267 }1272 }
1268 }1273 }
@@ -1270,7 +1275,7 @@
1270 pt_current = pt_tokenizer->nextToken(self);1275 pt_current = pt_tokenizer->nextToken(self);
1271 if (pt_current->isKeyWord("TO"))1276 if (pt_current->isKeyWord("TO"))
1272 pt_current = pt_tokenizer->nextToken(self);1277 pt_current = pt_tokenizer->nextToken(self);
1273 parseQualifiedName(self, name);1278 parseQualifiedName(self, NULL, name);
1274 }1279 }
1275 else1280 else
1276 /* Just ignore the syntax until the next , */1281 /* Just ignore the syntax until the next , */
@@ -1295,7 +1300,7 @@
1295 else if (pt_current->isKeyWord("SPACIAL"))1300 else if (pt_current->isKeyWord("SPACIAL"))
1296 pt_current = pt_tokenizer->nextToken(self);1301 pt_current = pt_tokenizer->nextToken(self);
1297 pt_current = pt_tokenizer->nextToken(self, "INDEX", pt_current);1302 pt_current = pt_tokenizer->nextToken(self, "INDEX", pt_current);
1298 parseQualifiedName(self, name);1303 parseQualifiedName(self, NULL, name);
1299 optionalIndexType(self);1304 optionalIndexType(self);
1300 pt_current = pt_tokenizer->nextToken(self, "ON", pt_current);1305 pt_current = pt_tokenizer->nextToken(self, "ON", pt_current);
1301 parseTableName(self, true);1306 parseTableName(self, true);
@@ -1310,7 +1315,7 @@
13101315
1311 pt_current = pt_tokenizer->nextToken(self, "DROP", pt_current);1316 pt_current = pt_tokenizer->nextToken(self, "DROP", pt_current);
1312 pt_current = pt_tokenizer->nextToken(self, "INDEX", pt_current);1317 pt_current = pt_tokenizer->nextToken(self, "INDEX", pt_current);
1313 parseQualifiedName(self, name);1318 parseQualifiedName(self, NULL, name);
1314 pt_current = pt_tokenizer->nextToken(self, "ON", pt_current);1319 pt_current = pt_tokenizer->nextToken(self, "ON", pt_current);
1315 parseTableName(self, true);1320 parseTableName(self, true);
1316 dropConstraint(self, name, XT_DD_INDEX);1321 dropConstraint(self, name, XT_DD_INDEX);
@@ -1351,7 +1356,7 @@
1351 virtual void addConstraint(XTThreadPtr self, char *name, u_int type, bool lastColumn);1356 virtual void addConstraint(XTThreadPtr self, char *name, u_int type, bool lastColumn);
1352 virtual void dropConstraint(XTThreadPtr self, char *name, u_int type);1357 virtual void dropConstraint(XTThreadPtr self, char *name, u_int type);
1353 virtual void addListedColumn(XTThreadPtr self, char *index_col_name);1358 virtual void addListedColumn(XTThreadPtr self, char *index_col_name);
1354 virtual void setReferencedTable(XTThreadPtr self, char *ref_table);1359 virtual void setReferencedTable(XTThreadPtr self, char *ref_schema, char *ref_table);
1355 virtual void addReferencedColumn(XTThreadPtr self, char *index_col_name);1360 virtual void addReferencedColumn(XTThreadPtr self, char *index_col_name);
1356 virtual void setActions(XTThreadPtr self, int on_delete, int on_update);1361 virtual void setActions(XTThreadPtr self, int on_delete, int on_update);
13571362
@@ -1546,23 +1551,31 @@
1546 }1551 }
1547}1552}
15481553
1549void XTCreateTable::setReferencedTable(XTThreadPtr self, char *ref_table)1554void XTCreateTable::setReferencedTable(XTThreadPtr self, char *ref_schema, char *ref_table)
1550{1555{
1551 XTDDForeignKey *fk = (XTDDForeignKey *) ct_curr_constraint;1556 XTDDForeignKey *fk = (XTDDForeignKey *) ct_curr_constraint;
1552 char path[PATH_MAX];1557 char path[PATH_MAX];
15531558
1554 xt_strcpy(PATH_MAX, path, ct_tab_path->ps_path);1559 if (ref_schema) {
1555 xt_remove_last_name_of_path(path);1560 xt_strcpy(PATH_MAX,path, ".");
1556 if (ct_convert) {1561 xt_add_dir_char(PATH_MAX, path);
1557 char buffer[XT_IDENTIFIER_NAME_SIZE];1562 xt_strcat(PATH_MAX, path, ref_schema);
1558 size_t len;1563 xt_add_dir_char(PATH_MAX, path);
1559
1560 myxt_static_convert_identifier(self, ct_charset, ref_table, buffer, XT_IDENTIFIER_NAME_SIZE);
1561 len = strlen(path);
1562 myxt_static_convert_table_name(self, buffer, &path[len], PATH_MAX - len);
1563 }
1564 else
1565 xt_strcat(PATH_MAX, path, ref_table);1564 xt_strcat(PATH_MAX, path, ref_table);
1565 } else {
1566 xt_strcpy(PATH_MAX, path, ct_tab_path->ps_path);
1567 xt_remove_last_name_of_path(path);
1568 if (ct_convert) {
1569 char buffer[XT_IDENTIFIER_NAME_SIZE];
1570 size_t len;
1571
1572 myxt_static_convert_identifier(self, ct_charset, ref_table, buffer, XT_IDENTIFIER_NAME_SIZE);
1573 len = strlen(path);
1574 myxt_static_convert_table_name(self, buffer, &path[len], PATH_MAX - len);
1575 }
1576 else
1577 xt_strcat(PATH_MAX, path, ref_table);
1578 }
15661579
1567 fk->fk_ref_tab_name = (XTPathStrPtr) xt_dup_string(self, path);1580 fk->fk_ref_tab_name = (XTPathStrPtr) xt_dup_string(self, path);
1568}1581}
@@ -2065,8 +2078,13 @@
20652078
2066void XTDDForeignKey::loadString(XTThreadPtr self, XTStringBufferPtr sb)2079void XTDDForeignKey::loadString(XTThreadPtr self, XTStringBufferPtr sb)
2067{2080{
2081 char schema_name[XT_IDENTIFIER_NAME_SIZE];
2082
2068 XTDDConstraint::loadString(self, sb);2083 XTDDConstraint::loadString(self, sb);
2069 xt_sb_concat(self, sb, " REFERENCES `");2084 xt_sb_concat(self, sb, " REFERENCES `");
2085 xt_2nd_last_name_of_path(XT_IDENTIFIER_NAME_SIZE, schema_name, fk_ref_tab_name->ps_path);
2086 xt_sb_concat(self, sb, schema_name);
2087 xt_sb_concat(self, sb, "`.`");
2070 xt_sb_concat(self, sb, xt_last_name_of_path(fk_ref_tab_name->ps_path));2088 xt_sb_concat(self, sb, xt_last_name_of_path(fk_ref_tab_name->ps_path));
2071 xt_sb_concat(self, sb, "` ");2089 xt_sb_concat(self, sb, "` ");
20722090
@@ -2877,9 +2895,33 @@
2877 return ok;2895 return ok;
2878}2896}
28792897
2880xtBool XTDDTable::checkCanDrop()2898/*
2899 * drop_db parameter is TRUE if we are dropping the schema of this table. In this case
2900 * we return TRUE if the table has only refs to the tables from its own schema
2901 */
2902xtBool XTDDTable::checkCanDrop(xtBool drop_db)
2881{2903{
2882 /* no refs or references only itself */2904 /* no refs or references only itself */
2883 return (dt_trefs == NULL) || 2905 if ((dt_trefs == NULL) || ((dt_trefs->tr_next == NULL) && (dt_trefs->tr_fkey->co_table == this)))
2884 ((dt_trefs->tr_next == NULL) && (dt_trefs->tr_fkey->co_table == this));2906 return TRUE;
2907
2908 if (!drop_db)
2909 return FALSE;
2910
2911 const char *this_schema = xt_last_2_names_of_path(dt_table->tab_name->ps_path);
2912 size_t this_schema_sz = xt_last_name_of_path(dt_table->tab_name->ps_path) - this_schema;
2913 XTDDTableRef *tr = dt_trefs;
2914
2915 while (tr) {
2916 const char *tab_path = tr->tr_fkey->co_table->dt_table->tab_name->ps_path;
2917 const char *tab_schema = xt_last_2_names_of_path(tab_path);
2918 size_t tab_schema_sz = xt_last_name_of_path(tab_path) - tab_schema;
2919
2920 if (this_schema_sz != tab_schema_sz || strncmp(this_schema, tab_schema, tab_schema_sz))
2921 return FALSE;
2922
2923 tr = tr->tr_next;
2924 }
2925
2926 return TRUE;
2885}2927}
28862928
=== modified file 'src/datadic_xt.h'
--- src/datadic_xt.h 2009-05-19 15:22:26 +0000
+++ src/datadic_xt.h 2009-06-12 14:29:30 +0000
@@ -288,7 +288,7 @@
288 XTDDIndex *findReferenceIndex(XTDDForeignKey *fk);288 XTDDIndex *findReferenceIndex(XTDDForeignKey *fk);
289 bool insertRow(struct XTOpenTable *rec_ot, xtWord1 *buffer);289 bool insertRow(struct XTOpenTable *rec_ot, xtWord1 *buffer);
290 bool checkNoAction(struct XTOpenTable *ot, xtRecordID rec_id);290 bool checkNoAction(struct XTOpenTable *ot, xtRecordID rec_id);
291 xtBool checkCanDrop();291 xtBool checkCanDrop(xtBool drop_db);
292 bool deleteRow(struct XTOpenTable *rec_ot, xtWord1 *buffer);292 bool deleteRow(struct XTOpenTable *rec_ot, xtWord1 *buffer);
293 void deleteAllRows(XTThreadPtr self);293 void deleteAllRows(XTThreadPtr self);
294 bool updateRow(struct XTOpenTable *rec_ot, xtWord1 *before, xtWord1 *after);294 bool updateRow(struct XTOpenTable *rec_ot, xtWord1 *before, xtWord1 *after);
295295
=== modified file 'src/ha_pbxt.cc'
--- src/ha_pbxt.cc 2009-06-10 16:26:33 +0000
+++ src/ha_pbxt.cc 2009-06-12 14:29:30 +0000
@@ -4682,7 +4682,7 @@
4682 pushr_(ha_release_exclusive_use, share);4682 pushr_(ha_release_exclusive_use, share);
4683 ha_close_open_tables(self, share, NULL);4683 ha_close_open_tables(self, share, NULL);
46844684
4685 xt_drop_table(self, (XTPathStrPtr) table_path);4685 xt_drop_table(self, (XTPathStrPtr) table_path, thd_sql_command(thd) == SQLCOM_DROP_DB);
46864686
4687 freer_(); // ha_release_exclusive_use(share)4687 freer_(); // ha_release_exclusive_use(share)
4688 freer_(); // ha_unget_share(share)4688 freer_(); // ha_unget_share(share)
46894689
=== modified file 'src/table_xt.cc'
--- src/table_xt.cc 2009-05-26 14:01:46 +0000
+++ src/table_xt.cc 2009-06-12 14:29:30 +0000
@@ -1590,7 +1590,7 @@
1590 exit_();1590 exit_();
1591}1591}
15921592
1593xtPublic void xt_drop_table(XTThreadPtr self, XTPathStrPtr tab_name)1593xtPublic void xt_drop_table(XTThreadPtr self, XTPathStrPtr tab_name, xtBool drop_db)
1594{1594{
1595 XTDatabaseHPtr db = self->st_database;1595 XTDatabaseHPtr db = self->st_database;
1596 XTOpenTablePoolPtr table_pool;1596 XTOpenTablePoolPtr table_pool;
@@ -1614,7 +1614,7 @@
1614 tab_id = tab->tab_id; /* tab is not null if returned table_pool is not null */1614 tab_id = tab->tab_id; /* tab is not null if returned table_pool is not null */
1615 /* check if other tables refer this */1615 /* check if other tables refer this */
1616 if (!self->st_ignore_fkeys) 1616 if (!self->st_ignore_fkeys)
1617 can_drop = tab->tab_dic.dic_table->checkCanDrop();1617 can_drop = tab->tab_dic.dic_table->checkCanDrop(drop_db);
1618 }1618 }
1619#ifdef DRIZZLED 1619#ifdef DRIZZLED
1620 /* See the comment in ha_pbxt::delete_table regarding different implmentation of DROP TABLE1620 /* See the comment in ha_pbxt::delete_table regarding different implmentation of DROP TABLE
16211621
=== modified file 'src/table_xt.h'
--- src/table_xt.h 2009-05-28 15:17:16 +0000
+++ src/table_xt.h 2009-06-12 14:29:30 +0000
@@ -514,7 +514,7 @@
514int xt_use_table_by_id(struct XTThread *self, XTTableHPtr *tab, struct XTDatabase *db, xtTableID tab_id);514int xt_use_table_by_id(struct XTThread *self, XTTableHPtr *tab, struct XTDatabase *db, xtTableID tab_id);
515XTOpenTablePtr xt_open_table(XTTableHPtr tab);515XTOpenTablePtr xt_open_table(XTTableHPtr tab);
516void xt_close_table(XTOpenTablePtr ot, xtBool flush, xtBool have_table_lock);516void xt_close_table(XTOpenTablePtr ot, xtBool flush, xtBool have_table_lock);
517void xt_drop_table(struct XTThread *self, XTPathStrPtr name);517void xt_drop_table(struct XTThread *self, XTPathStrPtr name, xtBool drop_db);
518void xt_check_table(XTThreadPtr self, XTOpenTablePtr tab);518void xt_check_table(XTThreadPtr self, XTOpenTablePtr tab);
519void xt_rename_table(struct XTThread *self, XTPathStrPtr old_name, XTPathStrPtr new_name);519void xt_rename_table(struct XTThread *self, XTPathStrPtr old_name, XTPathStrPtr new_name);
520520
521521
=== modified file 'test/mysql-test/r/pbxt_bugs.result'
--- test/mysql-test/r/pbxt_bugs.result 2009-06-10 16:26:33 +0000
+++ test/mysql-test/r/pbxt_bugs.result 2009-06-12 14:29:30 +0000
@@ -1230,3 +1230,25 @@
1230312303
1231412314
1232drop table child, parent;1232drop table child, parent;
1233create schema test378222;
1234use test378222;
1235create table t1 (id int primary key);
1236create table t2 (id int primary key);
1237alter table t1 add constraint foreign key (id) references t2 (id);
1238alter table t2 add constraint foreign key (id) references t1 (id);
1239drop schema test378222;
1240create schema test378222a;
1241create schema test378222b;
1242create table test378222a.t1 (id int primary key) engine = pbxt;
1243create table test378222b.t2 (id int primary key) engine = pbxt;
1244alter table test378222a.t1 add constraint foreign key (id) references test378222b.t2 (id);
1245alter table test378222b.t2 add constraint foreign key (id) references test378222a.t1 (id);
1246set foreign_key_checks = 1;
1247drop schema test378222a;
1248ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
1249drop schema test378222b;
1250ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
1251set foreign_key_checks = 0;
1252drop schema test378222a;
1253drop schema test378222b;
1254set foreign_key_checks = 1;
12331255
=== modified file 'test/mysql-test/t/pbxt_bugs.test'
--- test/mysql-test/t/pbxt_bugs.test 2009-06-10 16:26:33 +0000
+++ test/mysql-test/t/pbxt_bugs.test 2009-06-12 14:29:30 +0000
@@ -938,7 +938,34 @@
938938
939drop table child, parent;939drop table child, parent;
940940
941# bug 378222: Drop sakila causes error: Cannot delete or update a parent row: a foreign key constraint fails
942
943create schema test378222;
944use test378222;
945create table t1 (id int primary key);
946create table t2 (id int primary key);
947alter table t1 add constraint foreign key (id) references t2 (id);
948alter table t2 add constraint foreign key (id) references t1 (id);
949drop schema test378222;
950
951create schema test378222a;
952create schema test378222b;
953create table test378222a.t1 (id int primary key) engine = pbxt;
954create table test378222b.t2 (id int primary key) engine = pbxt;
955alter table test378222a.t1 add constraint foreign key (id) references test378222b.t2 (id);
956alter table test378222b.t2 add constraint foreign key (id) references test378222a.t1 (id);
957set foreign_key_checks = 1;
958--error 1217
959drop schema test378222a;
960--error 1217
961drop schema test378222b;
962set foreign_key_checks = 0;
963drop schema test378222a;
964drop schema test378222b;
965set foreign_key_checks = 1;
966
941--disable_query_log967--disable_query_log
968use test;
942DROP TABLE t2, t5;969DROP TABLE t2, t5;
943drop database pbxt;970drop database pbxt;
944--enable_query_log971--enable_query_log

Subscribers

People subscribed via source and target branches