简体   繁体   English

MySQL / mariadb innodb:行大小是否会影响复杂的查询性能?

[英]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). 我的MariaDB 10服务器上有一个具有数百万行(统计事件)的InnoDB表,历史上每一行都有一个长的user-id char(44)字段(用作非唯一键)以及其他30个int / varchar字段(行大小) (大约240个字节)。 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. 现在,我有机会添加4字节的int字段,并将其用作用户ID和所有查询的主要非唯一键。 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. 但是由于实现细节,我需要在此表中保留旧的符号char(44)用户ID-一些数据源不是我的,仅发送具有符号用户ID的事件。

So the question is: will - in general - keeping or removing this char(44) field affect performance of complex queries? 因此,问题是:通常来说,保留或删除此char(44)字段会影响复杂查询的性能吗? It will just stay like other char fields, and it will not be used as a key in queries anymore. 它只会像其他char字段一样保留,并且不再用作查询的键。 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. 对Aria进行了测试,发现对于我的目的,即使在简单的连接上,它也比InnoDB慢1.5倍。 InnoDB with "redundant" row format works even faster. 具有“冗余”行格式的InnoDB的运行速度甚至更快。 So - no, Aria is not a compromise, it is even slower than myISAM. 所以-不,Aria不是妥协,它甚至比myISAM慢。 I suppose InnoDB is XtraDB in Maria10, this explains the speed. 我想InnoDB是Maria10中的XtraDB,这说明了速度。

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. 还对自连接查询进行了一些测试,发现如果不使用此字段,则保留或删除char(44)字段不会对查询性能产生影响。

And moving from char(44) key to int makes queries 2x faster! 从char(44)键移到int可使查询速度提高2倍!

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. 如前所述,将更多的RAM和/或某些SSD磁盘填充到数据库服务器中的成本很可能比重构程序要少。

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. 那么(character_user_id)上的复合索引将使此查询非常快速。

Be careful when you add lots of indexes: there's a penalty to pay upon INSERT or UPDATE in tables with many indexes. 添加大量索引时要小心:在具有多个索引的表中对INSERT或UPDATE会付出一定的代价。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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