No, I hadn't run an EXPLAIN on the query, but I have now, using phpMyAdmin.
Firstly, I ran an EXPLAIN on the query with the tables optimized.
Then, I reloaded my data (which performs a TRUNCATE first), and ran the EXPLAIN again.
(Followed very quickly by optimizing all the tables again!)
I was not familiar with the output of EXPLAIN for MySQL, but having read the documentation, my interpretation is as follows....
User Profile
Collapse
-
Yes, I agree, the uniqueness of index I1 is enforced, but the cardinality still shows as null. This implies to me that the index is present, but it's no use unless My SQL knows about it when it determines the best execution plan....Leave a comment:
-
My test case used only 2 rows, but in my live environment, the same results were there even after inserting more than 2,500 rows.
If MySQL determines its SQL execution plan based on what it knows about index cardinality and it sees NULL, then whether the index is present or not, this would cause the problem I was experiencing. Not too much of an overhead when processing a single table, but my code included multiple tables including...Leave a comment:
-
Test case, simplified to the minimum below: -
...Code:DROP TABLE IF EXISTS Tester; CREATE TABLE Tester ( ID INT(11) NOT NULL, F1 VARCHAR(10) NOT NULL, F2 VARCHAR(10) NOT NULL, F3 VARCHAR(10) NOT NULL, F4 VARCHAR(10) NOT NULL, F5 DATETIME NOT NULL, F6 TEXT NOT NULL, PRIMARY KEY (ID), UNIQUE I1 (F1, F2), KEY I2 (F3, F4), KEY I3 (F4),
Leave a comment:
-
I discarded the scripts and the data that I used to perform the test, but it was based on the table that had originally caused me the problem. There were 35 columns in this table, and some of it was sensitive data.
I will look at recreating a simple test case when I get chance, possibly later today....Leave a comment:
-
After experimenting, it is not the TRUNCATE which disables the INDEXes - they are not activated from the time of the CREATE TABLE.
I created a copy of my table in another database.
There is a PRIMARY INDEX, a UNIQUE INDEX and 5 other INDEXes.
Running an OPTIMIZE TABLE or ANALYZE TABLE on the empty table returns 'Table is already up to date'.
INSERT INTO one or more rows and the PRIMARY INDEX...Leave a comment:
-
Thanks for the advice, but not currently an option.
I'm running on a shared hosting system and because I was losing several indexes, my queries started performing badly (MySQL server overload), and my MySQL database was turned off - twice!
It was only after the second occurrence that I managed to get enough information to find out what was causing the problem.
Oh, and I have only just recently signed...Leave a comment:
-
Index disabled after TRUNCATE
I have a series of tables in which the data can be refreshed from a file.
Before refreshing the data, some of the tables are cleared using either TRUNCATE or DELETE.
If TRUNCATE is used, any index which is not PRIMARY or UNIQUE appears to be disabled and is not updated when new data is inserted into the table.
Performing an OPTIMIZE reactivates the index.
If DELETE is used instead of TRUNCATE,...
No activity results to display
Show More
Leave a comment: