MySQL drop index bug

Source: Internet
Author: User

Problem description:

When drop index index_name on table_name, if table_name is in upper case, it will cause access to the information_schema.statistics table in the future.

Environment: MySQL 5.1.46 Win32 version.

Example:

Use test;

Create Table if not exists tci_inst

(

Fciid
Int unsigned,

Fcidver
Int unsigned,

Fciname
Varchar (256)

);

Create index ind_tci_fciid on tci_inst (fciid, fcidver );

Select * From information_schema.statistics where table_name = 'tci _ inst' and index_name = 'ind _ tci_fciid ';

Two records should be output. Two records are actually output, correct!

Select count (*) from information_schema.statistics where table_name = 'tci _ inst' and index_name = 'ind _ tci_fciid ';

2 should be output. Actual output 2, correct!
Drop index ind_tci_fciid on tci_inst; (Note that tci_inst is capitalized here)

Select * From information_schema.statistics where table_name = 'tci _ inst' and index_name = 'ind _ tci_fciid ';

0 records should be output. Correct!

Select count (*) from information_schema.statistics where table_name = 'tci _ inst' and index_name = 'ind _ tci_fciid ';

0 should be output, but 2 is output! Error !!!

Select table_name, index_nameFrom information_schema.statistics where table_name = 'tci _ inst' and index_name = 'ind _ tci_fciid ';

Two records can be output! Error !!!

If drop index ind_tci_fciid on tci_inst; (change to lower case here)

Then everything is normal.


Source:

I have studied the problem of drop index if exists today and found this problem when studying this problem.

Because MySQL does not support drop index if exists, it is troublesome to write the installation/upgrade script,

Therefore, a stored procedure is written for judgment and deletion.

Determine whether the index exists by judging the table_name and index_name of information_schema.statistics.

If yes, delete the index.

However, since all tables are created in uppercase, the stored procedure is also called with an uppercase table name,

The first execution is correct. When the second execution is performed, the system should judge that the table index does not exist. However, due to this bug, the system misjudges the existence.

Correct only after restart MySQL

Improvement:

During the study of MySQL, maybe the table names should all be set to lower case?

In MySQL programming, tables are all named in lower case?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.