There is most definitely a difference between SHOW STATUS;
and SHOW GLOBAL STATUS;
SHOW GLOBAL STATUS;
will give you status variables that have updated since mysqld started for all sessions that are connected or have ever been connected.
SHOW STATUS;
will give you status variables that have updated within your session. The command can also be expressed as SHOW SESSION STATUS;
(As the MySQL Documentation says, it displays the status values for the current connection).
To physically show the difference, the information_schema database has them separated as
INFORMATION_SCHEMA.GLOBAL_STATUS
INFORMATION_SCHEMA.SESSION_STATUS
These information_schema tables have been around since MySQL 5.1.12.
Why the difference?
To thoroughly demonstrate the difference, let me run an INNER JOIN of these tables to show which values are different. Here is the query:
SELECT a.variable_name,a.variable_value,b.variable_value
FROM information_schema.global_status A INNER join information_schema.session_status B
USING (variable_name) WHERE A.variable_value <> B.variable_value;
Please note the output:
mysql> SELECT A.variable_name,A.variable_value,B.variable_value
-> FROM information_schema.global_status A INNER join information_schema.session_status B
-> USING (variable_name) WHERE A.variable_value <> B.variable_value;
+---------------------------+----------------+----------------+
| variable_name | variable_value | variable_value |
+---------------------------+----------------+----------------+
| BYTES_RECEIVED | 123641576598 | 7757 |
| BYTES_SENT | 149888451047 | 300001 |
| COM_ADMIN_COMMANDS | 121915 | 0 |
| COM_ALTER_TABLE | 111 | 0 |
| COM_BEGIN | 1 | 0 |
| COM_CALL_PROCEDURE | 530 | 0 |
| COM_CHANGE_DB | 1623 | 1 |
| COM_COMMIT | 19220 | 0 |
| COM_CREATE_FUNCTION | 4 | 0 |
| COM_CREATE_PROCEDURE | 126 | 0 |
| COM_CREATE_TABLE | 354 | 0 |
| COM_DEALLOC_SQL | 924 | 0 |
| COM_DELETE | 64668 | 0 |
| COM_DELETE_MULTI | 19 | 0 |
| COM_DROP_FUNCTION | 4 | 0 |
| COM_DROP_PROCEDURE | 148 | 0 |
| COM_DROP_TABLE | 238 | 0 |
| COM_EXECUTE_SQL | 945 | 0 |
| COM_INSERT | 1182379 | 0 |
| COM_INSERT_SELECT | 40673 | 0 |
| COM_KILL | 68 | 0 |
| COM_LOAD | 22386 | 0 |
| COM_LOCK_TABLES | 2 | 0 |
| COM_OPTIMIZE | 2 | 0 |
| COM_PREPARE_SQL | 948 | 0 |
| COM_REPAIR | 8 | 0 |
| COM_REPLACE | 34737 | 0 |
| COM_ROLLBACK | 13 | 0 |
| COM_SELECT | 1107225018 | 65 |
| COM_SET_OPTION | 602159 | 0 |
| COM_SHOW_BINLOGS | 8 | 0 |
| COM_SHOW_CHARSETS | 12 | 0 |
| COM_SHOW_COLLATIONS | 100 | 0 |
| COM_SHOW_CREATE_DB | 6 | 0 |
| COM_SHOW_CREATE_FUNC | 2453 | 0 |
| COM_SHOW_CREATE_PROC | 5684 | 0 |
| COM_SHOW_CREATE_TABLE | 1313 | 0 |
| COM_SHOW_DATABASES | 275 | 0 |
| COM_SHOW_EVENTS | 1 | 0 |
| COM_SHOW_FIELDS | 13666 | 1 |
| COM_SHOW_FUNCTION_STATUS | 362 | 0 |
| COM_SHOW_KEYS | 494 | 0 |
| COM_SHOW_PLUGINS | 2 | 0 |
| COM_SHOW_PROCEDURE_STATUS | 361 | 0 |
| COM_SHOW_PROCESSLIST | 488943 | 15 |
| COM_SHOW_SLAVE_STATUS | 4 | 0 |
| COM_SHOW_STATUS | 12315 | 10 |
| COM_SHOW_STORAGE_ENGINES | 30 | 0 |
| COM_SHOW_TABLE_STATUS | 320 | 0 |
| COM_SHOW_TABLES | 584 | 0 |
| COM_SHOW_TRIGGERS | 2 | 0 |
| COM_SHOW_VARIABLES | 190 | 1 |
| COM_STMT_CLOSE | 924 | 0 |
| COM_STMT_EXECUTE | 945 | 0 |
| COM_STMT_PREPARE | 948 | 0 |
| COM_TRUNCATE | 522 | 0 |
| COM_UNLOCK_TABLES | 2 | 0 |
| COM_UPDATE | 496041 | 0 |
| COM_UPDATE_MULTI | 625 | 0 |
| CREATED_TMP_DISK_TABLES | 16772 | 40 |
| CREATED_TMP_TABLES | 34336 | 63 |
| HANDLER_COMMIT | 1109540769 | 0 |
| HANDLER_DELETE | 12775993 | 0 |
| HANDLER_EXTERNAL_LOCK | 2228108102 | 24 |
| HANDLER_PREPARE | 2155764 | 0 |
| HANDLER_READ_FIRST | 23586 | 9 |
| HANDLER_READ_KEY | 18285349400 | 0 |
| HANDLER_READ_LAST | 13000 | 0 |
| HANDLER_READ_NEXT | 72142303428 | 0 |
| HANDLER_READ_PREV | 3000146 | 0 |
| HANDLER_READ_RND | 1261418742 | 156 |
| HANDLER_READ_RND_NEXT | 12320861765 | 7845 |
| HANDLER_ROLLBACK | 269376 | 0 |
| HANDLER_UPDATE | 2596924399 | 0 |
| HANDLER_WRITE | 8200421074 | 8241 |
| LAST_QUERY_COST | 0.000000 | 21.399123 |
| LAST_QUERY_PARTIAL_PLANS | 0 | 3 |
| OPENED_TABLE_DEFINITIONS | 2482 | 0 |
| OPENED_TABLES | 3619 | 0 |
| QUESTIONS | 1110214247 | 97 |
| SELECT_FULL_JOIN | 615 | 9 |
| SELECT_RANGE | 243635 | 0 |
| SELECT_SCAN | 47851 | 53 |
| SLOW_QUERIES | 29290 | 50 |
| SORT_MERGE_PASSES | 6 | 0 |
| SORT_RANGE | 179956 | 0 |
| SORT_ROWS | 321609927 | 156 |
| SORT_SCAN | 1829 | 39 |
| TABLE_OPEN_CACHE_HITS | 1109365721 | 13 |
| TABLE_OPEN_CACHE_MISSES | 1669 | 0 |
+---------------------------+----------------+----------------+
90 rows in set (0.03 sec)
mysql>
Look at four variables:
| BYTES_RECEIVED | 123641576598 | 7757 |
| BYTES_SENT | 149888451047 | 300001 |
| COM_ADMIN_COMMANDS | 121915 | 0 |
| COM_SHOW_PROCESSLIST | 488955 | 15 |
What does this tell you?
- mysqld received 123,641,576,598 bytes (115.15GB) from all DB Connections since mysqld started
- The session I ran the query with received 7,757 bytes (a little over 7K) in my current session
- mysqld sent 149,888,451,047 bytes (139.59GB) from all DB Connections since mysqld started
- The session I ran the query with sent 300,001 bytes (a little under 297K) in my current session
- There have been 121,915 administrative commands that have run since mysqld started
- There have benn 0 administrative commands that have run in my current session
- The command
SHOW PROCESSLIST
has been run 488,955 times since mysqld started
- The command
SHOW PROCESSLIST
has been run 15 times in my current session
You can compare the other 86 varibales and interpret them the same way.
Give it a Try !!!
YOUR QUERY
SELECT post.postid, post.attach FROM newbb_innopost AS post WHERE post.threadid = 51506;
At first glance, that query should only touches 1.1597% (62510 out of 5390146) of the table. It should be fast given the key distribution of threadid 51506.
REALITY CHECK
No matter which version of MySQL (Oracle, Percona, MariaDB) you use, none of them can fight to one enemy they all have in common : The InnoDB Architecture.
CLUSTERED INDEX
Please keep in mind that the each threadid entry has a primary key attached. This means that when you read from the index, it must do a primary key lookup within the ClusteredIndex (internally named gen_clust_index). In the ClusteredIndex, each InnoDB page contains both data and PRIMARY KEY index info. See my post Best of MyISAM and InnoDB for more info.
REDUNDANT INDEXES
You have a lot of clutter in the table because some indexes have the same leading columns. MySQL and InnoDB has to navigate through the index clutter to get to needed BTREE nodes. You should reduced that clutter by running the following:
ALTER TABLE newbb_innopost
DROP INDEX threadid,
DROP INDEX threadid_2,
DROP INDEX threadid_visible_dateline,
ADD INDEX threadid_visible_dateline_index (`threadid`,`visible`,`dateline`,`userid`)
;
Why strip down these indexes ?
- The first three indexes start with threadid
threadid_2
and threadid_visible_dateline
start with the same three columns
threadid_visible_dateline
does not need postid since it's the PRIMARY KEY and it's embedded
BUFFER CACHING
The InnoDB Buffer Pool caches data and index pages. MyISAM only caches index pages.
Just in this area alone, MyISAM does not waste time caching data. That's because it's not designed to cache data. InnoDB caches every data page and index page (and its grandmother) it touches. If your InnoDB Buffer Pool is too small, you could be caching pages, invalidating pages, and removing pages all in one query.
TABLE LAYOUT
You could shave of some space from the row by considering importthreadid
and importpostid
. You have them as BIGINTs. They take up 16 bytes in the ClusteredIndex per row.
You should run this
SELECT importthreadid,importpostid FROM newbb_innopost PROCEDURE ANALYSE();
This will recommend what data types these columns should be for the given dataset.
CONCLUSION
MyISAM has a lot less to contend with than InnoDB, especially in the area of caching.
While you revealed the amount of RAM (32GB
) and the version of MySQL (Server version: 10.0.12-MariaDB-1~trusty-wsrep-log mariadb.org binary distribution, wsrep_25.10.r4002
), there are still other pieces to this puzzle you have not revealed
- The InnoDB settings
- The Number of Cores
- Other settings from
my.cnf
If you can add these things to the question, I can further elaborate.
UPDATE 2014-08-28 11:27 EDT
You should increase threading
innodb_read_io_threads = 64
innodb_write_io_threads = 16
innodb_log_buffer_size = 256M
I would consider disabling the query cache (See my recent post Why query_cache_type is disabled by default start from MySQL 5.6?)
query_cache_size = 0
I would preserve the Buffer Pool
innodb_buffer_pool_dump_at_shutdown=1
innodb_buffer_pool_load_at_startup=1
Increase purge threads (if you do DML on multiple tables)
innodb_purge_threads = 4
GIVE IT A TRY !!!
Best Answer
You have two things running into each other
Issue #1 : Differing Queries
Look at your three queries
Each query stores a unique result (if the results are stored). If the results are too big (as in the case of the second and third queries), the result sets must be retrieved again.
You could potentially solve this with a bigger query cache, which must be big enough to hold each query's result set. This leads us into ...
Issue #2 : InnoDB Storage Engine
Unfortunately, the InnoDB Storage Engine likes to play traffic cop with the query cache. I had discussed this before in my answer to Is the overhead of frequent query cache invalidation ever worth it? where I learned this pages 213-215 in the book (Second Edition)
If you really want the query cache, you have to meticulously set the query cache size to suit your needs. In almost all cases, it is best to set query_cache_size to 0 when dealing with InnoDB.
First, add this to
my.cnf
Then, run this
and you should be all set.
Give it a Try !!!