A Parting Shot

mysql> INSERT IGNORE INTO trickyTable (id) VALUES (1);
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT * FROM trickyTable;
Empty set (0.00 sec)

That’s odd – what happened to the row?

I have the necessary privileges:

mysql> SHOW GRANTS;
+---------------------------------------------------+
| Grants for root@localhost                         |
+---------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' |
+---------------------------------------------------+
1 row in set (0.00 sec)

The table exists:

mysql> SHOW TABLES;
+------------------------+
| Tables_in_example      |
+------------------------+
| trickytable            |
+------------------------+
1 row in set (0.00 sec)

The field is there and adequately typed for the value:

mysql> DESCRIBE trickyTable;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id    | int(11) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
1 row in set (0.02 sec)

Not using BLACKHOLE, and no transaction tricks:

mysql> SELECT engine FROM information_schema.tables WHERE table_name = 'trickyTable';
+--------+
| engine |
+--------+
| MyISAM |
+--------+
1 row in set (0.00 sec)

No triggers to make things tricky:

mysql> SELECT * FROM information_schema.triggers WHERE event_object_table = 'trickyTable';
Empty set (0.00 sec)

Just take my word for it that I’m not using Proxy, and this has nothing to do with replication.

Comments

13 responses to “A Parting Shot”

  1. jd Avatar
    jd

    must have something to do with case.
    insert is to trickyTable
    show tables is trickytable
    or they are two different tables.

  2. snoyes Avatar

    Nothing to do with identifier case. This happens to be on a Windows box, but on Linux I’d just turn on lower case table names.

  3. Don McArthur Avatar

    IGNORE is the trick, I think, which causes errors to be treated as warnings. Do ‘SHOW WARNINGS;’ and display the results, please.

  4. Giuseppe Maxia Avatar

    Using MySQL 5.1

    set global event_scheduler=1;
    create event e1 on schedule every 1 second do truncate trickytable;

  5. Giuseppe Maxia Avatar

    I think I got it:

    create table trickytable (id int) partition by list (id) (partition p1 values in (2));

  6. snoyes Avatar

    Don: Sure.

    mysql> INSERT IGNORE INTO trickyTable (id) VALUES (1);
    Query OK, 0 rows affected (0.00 sec)

    mysql> SHOW WARNINGs;
    Empty set (0.00 sec)

  7. snoyes Avatar

    Giuseppe: Event scheduler wouldn’t do it – the INSERT statement reported 0 rows affected.

  8. ryan Avatar
    ryan

    A blackhole temporary table comes close, but shows 1 row inserted instead of the zero your example shows.

    mysql> create table trickyTable (id int) engine=myisam;
    Query OK, 0 rows affected (0.00 sec)

    mysql> create temporary table trickyTable (id int) engine=blackhole;
    Query OK, 0 rows affected (0.00 sec)

    mysql> INSERT IGNORE INTO trickyTable (id) VALUES (1);
    Query OK, 1 row affected (0.00 sec)

    mysql> SELECT * FROM trickyTable;
    Empty set (0.00 sec)

    (and then your I_S queries pick up the myisam table)

  9. XL Avatar
    XL

    A compressed MyISAM table?

  10. XL Avatar
    XL

    Hmm. No. Compressed (=readonly) table gives an error.

  11. Sheeri K. Cabral Avatar

    hrm, a federated table perhaps?

  12. […] partitions to create constraints A devilish quiz by Scott Noyes has made me thinking about a side effect of partitioning.The quiz Given a table […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.