简体   繁体   中英

Mysql/mariadb innodb: does row size affect complex query performance?

I have InnoDB table with millions rows (statistics events) on my MariaDB 10 server and each row historically has a long user-id char(44) field (used as non-unique key) along with other 30 int/varchar fields (row size is about 240 bytes). My system can make cohort analysis, funnels, event segmentation and other common statistics - so some queries are very complex with many joins. Now I have an opportunity to add 4-byte int field and use it as user-id and as main non-unique key for all queries. But I need to keep old symbolic char(44) user-id in this table because of realization details - some data sources are not mine and send events only with symbolic user-ids.

So the question is: will - in general - keeping or removing this char(44) field affect performance of complex queries? It will just stay like other char fields, and it will not be used as a key in queries anymore. I'd prefer not to split the table because there are lot of code depend on its structure.

Thanks!


Tested Aria, and found out that it is ~1.5x slower than InnoDB for my purposes, even on simple joins. InnoDB with "redundant" row format works even faster. So - no, Aria is not a compromise, it is even slower than myISAM. I suppose InnoDB is XtraDB in Maria10, this explains the speed.

Also did some testing on self join query and found that leaving or removing char(44) field has no affect on query performance if we're not using this field.

And moving from char(44) key to int makes queries 2x faster!

Switching to a shorter integer key will help query performance a little bit. The indexing overhead of fixed length character columns isn't hideous.

Stuffing more RAM and/or some SSD disks into your database server will most likely cost less than refactoring your program, as you have mentioned.

What will really help your query performance is the creation of appropriate compound covering indexes . If you have queries that can be satisfied just from such an index, things will get faster.

For example, if you do a lot of

SELECT integer_user_id
  FROM table
 WHERE character_user_id = 'constant'

then a compound index on (character_user_id) will make this query very fast.

Be careful when you add lots of indexes: there's a penalty to pay upon INSERT or UPDATE in tables with many indexes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM