Giter Club home page Giter Club logo

Comments (4)

nerdling avatar nerdling commented on June 14, 2024

I'm looking at #14 but it did not remove the old index as far as I can tell. Also, the composite key that was added is useless as it searches for ip then qid, even though qid is queried first.

from wp-polls.

lesterchan avatar lesterchan commented on June 14, 2024

Oh yes. That is a typo. What do you suggest for #14 actually? I tested theKEY pollip_ip_qid (pollip_ip, pollip_qid) against https://gist.github.com/archon810/0f6bb97e5a7e29e4d1e9, it seems ok to me. But having said, that I am no way a MySQL expert

from wp-polls.

nerdling avatar nerdling commented on June 14, 2024

For me the composite qid/ip key is not picked due to key order. Are the keys created in the same order as my gist?
https://gist.github.com/nerdling/09b84495e3aebef4bc58

Since they're the same cardinality, whichever is the first key gets used. This means they're effectively duplicates, so the former will never be used.

from wp-polls.

lesterchan avatar lesterchan commented on June 14, 2024

I am not too sure whether they are created in the same order. But you are right, the composite key has no effect!

mysql> show keys from wp_pollsip;
+------------+------------+---------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table      | Non_unique | Key_name      | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+------------+------------+---------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| wp_pollsip |          0 | PRIMARY       |            1 | pollip_id   | A         |       44773 |     NULL | NULL   |      | BTREE      |         |               |
| wp_pollsip |          1 | pollip_ip     |            1 | pollip_ip   | A         |       44773 |     NULL | NULL   |      | BTREE      |         |               |
| wp_pollsip |          1 | pollip_qid    |            1 | pollip_qid  | A         |          18 |     NULL | NULL   |      | BTREE      |         |               |
| wp_pollsip |          1 | pollip_ip_qid |            1 | pollip_ip   | A         |       44773 |     NULL | NULL   |      | BTREE      |         |               |
| wp_pollsip |          1 | pollip_ip_qid |            2 | pollip_qid  | A         |       44773 |     NULL | NULL   |      | BTREE      |         |               |
+------------+------------+---------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
mysql> DROP INDEX `pollip_ip_qid` ON wp_pollsip;
Query OK, 44773 rows affected (0.45 sec)
Records: 44773  Duplicates: 0  Warnings: 0
mysql> show keys from wp_pollsip;
+------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table      | Non_unique | Key_name   | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| wp_pollsip |          0 | PRIMARY    |            1 | pollip_id   | A         |       44773 |     NULL | NULL   |      | BTREE      |         |               |
| wp_pollsip |          1 | pollip_ip  |            1 | pollip_ip   | A         |       44773 |     NULL | NULL   |      | BTREE      |         |               |
| wp_pollsip |          1 | pollip_qid |            1 | pollip_qid  | A         |          18 |     NULL | NULL   |      | BTREE      |         |               |
+------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
3 rows in set (0.00 sec)
mysql> explain SELECT pollip_aid FROM wp_pollsip WHERE pollip_ip = '75.82.197.50' AND pollip_qid = 7;
+----+-------------+------------+------+----------------------+-----------+---------+-------+------+-------------+
| id | select_type | table      | type | possible_keys        | key       | key_len | ref   | rows | Extra       |
+----+-------------+------------+------+----------------------+-----------+---------+-------+------+-------------+
|  1 | SIMPLE      | wp_pollsip | ref  | pollip_ip,pollip_qid | pollip_ip | 102     | const |   14 | Using where |
+----+-------------+------------+------+----------------------+-----------+---------+-------+------+-------------+
1 row in set (0.00 sec)
mysql> ALTER TABLE wp_pollsip ADD INDEX pollip_ip_qid (pollip_ip, pollip_qid);
Query OK, 44773 rows affected (0.46 sec)
Records: 44773  Duplicates: 0  Warnings: 0
mysql> explain SELECT pollip_aid FROM wp_pollsip WHERE pollip_ip = '75.82.197.50' AND pollip_qid = 7;
+----+-------------+------------+------+------------------------------------+---------------+---------+-------+------+-------------+
| id | select_type | table      | type | possible_keys                      | key           | key_len | ref   | rows | Extra       |
+----+-------------+------------+------+------------------------------------+---------------+---------+-------+------+-------------+
|  1 | SIMPLE      | wp_pollsip | ref  | pollip_ip,pollip_qid,pollip_ip_qid | pollip_ip_qid | 102     | const |   13 | Using where |
+----+-------------+------------+------+------------------------------------+---------------+---------+-------+------+-------------+
1 row in set (0.00 sec)

from wp-polls.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.