MyISAM

Why to use foreign keys with no action on delete or update

元气小坏坏 提交于 2019-12-12 07:14:52
问题 I have a question of interest: I have 2 tables in mysql with InnoDb . table tbl_a has a primary key, named a_id ; table tbl_b has a primary b_id and a foreign key on tbl_a.a_id with " ON DELETE NO ACTION ". +-------------+---------------+---------------+ | Table Name | Primary Key | Foreign Key | +-------------+---------------+---------------+ | tbl_a | a_id | | | tbl_b | b_id | a_id | +-------------+---------------+---------------+ why should I still use InnoDb and foreign keys, if i don't

SUM with a pivot to calculate overall score

微笑、不失礼 提交于 2019-12-12 03:57:41
问题 From another question I got this query to get my scores summed up properly: SELECT callSign,event, SUM(score) FROM scores LEFT JOIN candidates ON scores.candidateID=candidates.id WHERE candidateID IN (SELECT id FROM candidates WHERE assessmentID='1321') GROUP BY event, callSign ORDER BY candidateID,event I get data that looks like: callSign event TotalScore Y209 Bridge 45 Y209 PSA 3 Y209 Team Analyst Exam 40 X125 PSA 1 X125 Team Analyst Exam 38 V023 Amazing Race Planning 37 What I need is

Indexing column with REPLACE function in mySQL

拈花ヽ惹草 提交于 2019-12-12 03:54:29
问题 May be a silly question to ask. I need to use this a lot in both join and where : REPLACE(table_a.column_1, '-', '') = REPLACE(table_b.column_2, '-', '') since bit data inconsistency from other companies' system Is that possible or any other database type can have index of a column with REPLACE function? eg: ALTER TABLE `table_a` ADD INDEX ( REPLACE(`column_1`, '-', '') ) ; Database Type: MyISAM 回答1: There is no such thing as computed column in MySQL. If you want to format some value to speed

MySQL索引的底层实现(MyISAM和InnoDB)

。_饼干妹妹 提交于 2019-12-12 02:48:21
参考:https://www.cnblogs.com/boothsun/p/8970952.html MySQL索引的底层实现(MyISAM和InnoDB) B+树 MyISAM的索引实现 InnoDB的索引实现 在MySQL中,索引属于存储引擎级别的概念,不同存储引擎对索引的实现方式是不同的。 B+树 MyISAM和InnoDB都使用了B+树,如果想学习一下B+树可以看一下这篇文章-> B树与B+树 MyISAM的索引实现 MyISAM引擎使用B+Tree作为索引结构,叶节点的data域存放的是数据记录的地址。下图是MyISAM索引的原理图: 这里设表一共有三列,假设我们以Col1为主键,则上图是一个MyISAM表的主索引(Primary key)示意。可以看出MyISAM的索引文件仅仅保存数据记录的地址。在MyISAM中,主索引和辅助索引(Secondary key)在结构上没有任何区别,只是主索引要求key是唯一的,而辅助索引的key可以重复。如果我们在Col2上建立一个辅助索引,则此索引的结构如下图所示: 同样也是一棵B+树,data域保存数据记录的地址。因此,MyISAM中索引检索的算法为首先按照B+Tree搜索算法搜索索引,如果指定的Key存在,则取出其data域的值,然后以data域的值为地址,读取相应数据记录。 MyISAM的索引方式也叫做“非聚集”的

MyISAM与InnoDB 的区别

时光总嘲笑我的痴心妄想 提交于 2019-12-12 02:27:51
MyISAM与InnoDB 的区别 MyISAM和InnoDB的区别 如何选择 一些问题 MyISAM和InnoDB的区别 InnoDB支持事务,MyISAM不支持,对于InnoDB每一条SQL语言都默认封装成事务,自动提交,这样会影响速度,所以最好把多条SQL语言放在begin和commit之间,组成一个事务; InnoDB支持外键,而MyISAM不支持。对一个包含外键的InnoDB表转为MYISAM会失败; InnoDB是聚集索引,使用B+Tree作为索引结构,数据文件是和(主键)索引绑在一起的(表数据文件本身就是按B+Tree组织的一个索引结构),必须要有主键,通过主键索引效率很高。但是辅助索引需要两次查询,先查询到主键,然后再通过主键查询到数据。因此,主键不应该过大,因为主键太大,其他索引也都会很大。 MyISAM是非聚集索引,也是使用B+Tree作为索引结构,索引和数据文件是分离的,索引保存的是数据文件的指针。主键索引和辅助索引是独立的。 也就是说:InnoDB的B+树主键索引的叶子节点就是数据文件,辅助索引的叶子节点是主键的值;而MyISAM的B+树主键索引和辅助索引的叶子节点都是数据文件的地址指针。 InnoDB不保存表的具体行数,执行select count(*) from table时需要全表扫描。而MyISAM用一个变量保存了整个表的行数

How should I handle duplicate entries' weights in MyISAM search index?

本秂侑毒 提交于 2019-12-12 02:15:48
问题 Question I am using the result of a myisam_ftdump to generate a search suggestions table. This process went smoothly, but many words appear in the index multiple times. Clearly, I could just SELECT distinct term FROM suggestions ORDER BY weight , but doesn't this penalize words for showing up more than once? If it does, is there a concise formula for merging the rows? If it does not, which rows should I keep (e.g., highest weighted, lowest weighted)? Example Data +-----+------------+---------

rsync and MyISAM tables

怎甘沉沦 提交于 2019-12-11 16:46:22
问题 I'm trying to use rsync to backup MySQL data. The tables use the MyISAM storage engine. My expectation was that after the first rsync, subsequent rsyncs would be very fast. It turns out, if the table data was changed at all, the operation slows way down. I did an experiment with a 989 MB MYD file containing real data: Test 1 - recopying unmodified data rsync -a orig.MYD copy.MYD takes a while as expected rsync -a orig.MYD copy.MYD instantaneous - speedup is in the millions Test 2 - recopying

Optimizing query that looks at a specific time window each day

*爱你&永不变心* 提交于 2019-12-11 15:55:46
问题 This is a followup to my previous question Optimizing query to get entire row where one field is the maximum for a group I'll change the names from what I used there to make them a little more memorable, but these don't represent my actual use-case (so don't estimate the number of records from them). I have a table with a schema like this: OrderTime DATETIME(6), Customer VARCHAR(50), DrinkPrice DECIMAL, Bartender VARCHAR(50), TimeToPrepareDrink TIME(6), ... I'd like to extract the rows from

mysqli_use_result() and concurrency

做~自己de王妃 提交于 2019-12-11 14:47:45
问题 According to the documentation at mysqli_use_result One should not use mysqli_use_result() if a lot of processing on the client side is performed, since this will tie up the server and prevent other threads from updating any tables from which the data is being fetched. Does this only pertain to myISAM tables or also for InnoDB? 回答1: Just checked: MyISAM locks, InnoDB doesn't lock: <?php $db = new mysqli() or die ("Cannot connect: " . mysqli_connect_error() . "\n"); $query = "SELECT * FROM

Do table locks scale? / Would row locks be more efficient for nested sets?

依然范特西╮ 提交于 2019-12-11 14:00:53
问题 I'm using nested sets to store hierarchical data in a MyISAM table; the table consists of several hierarchical sets for each user. Each user will be the only one writing to his respective trees, but other users may read from them. Node deletion / Insertion requires that other rows in the same tree have their lft and rgt values updated, potentially hundreds of rows. In order to do this, I need to get a table write lock, update the other nodes in the tree, delete/insert the row and unlock the