我有一个查询,可以在表格中插入4个字段。我必须在其中的两个字段中对索引进行子字符串索引。
这是我的查询,但需要一段时间。有什么提示可以加快速度吗?
INSERT INTO tblmatch (subactivity_user,activity_user,activity_result,subactivity_result)
SELECT SUBSTRING_INDEX(a.activity,'/',1), a.activity, b.activity,SUBSTRING_INDEX(b.activity,'/',1)
FROM tbluser a, results b
WHERE SUBSTRING_INDEX(a.activity,'/',1) = SUBSTRING_INDEX(b.activity,'/',1)
AND a.activity NOT IN( b.activity)
这就是创建tblmatch的方法
CREATE TABLE tblmatch (
subactivity_user varchar(100) NOT NULL,
activity_user varchar(200) NOT NULL,
activity_result varchar(100) NOT NULL,
subactivity_result varchar(200) NOT NULL,
INDEX activity_result (activity_result))
这是结果表设置
CREATE TABLE results (
name varchar(100) NOT NULL,
activity varchar(250) NOT NULL,
count int(6) NOT NULL,
countlast int(6) NOT NULL,
INDEX activity (activity),
UNIQUE INDEX activity_2 (activity)
)
以下是从文本文件获取数据的示例。
<item component="ComponentInfo{au.com.phil.abduction2.demo/au.com.phil.abduction2.demo.menus.PsymIntro}" drawable="abduction" />
以下是我最初获取数据的方式。
LOAD DATA LOCAL INFILE '$ptmpName'
INTO TABLE tbluser
LINES STARTING BY '{'
TERMINATED BY '\" />' (@name,@activity)
set name=SUBSTRING_INDEX(@name,'\"',-1),
activity=SUBSTRING_INDEX(@name,'}',1)
这是tbluser setup
CREATE TABLE tbluser (
name varchar(100) NOT NULL,
activity varchar(200) NOT NULL,
INDEX activity (activity)
)
更新 我更新了我的tbluser和原始的方法来获取数据。这对桌子来说是一个很好的设置吗?
CREATE TABLE tbluser (
name varchar(100) NOT NULL,
activity_full varchar(200) NOT NULL,
activity varchar(100) NOT NULL,
class varchar(100) NOT NULL,
PRIMARY KEY (activity_full),
UNIQUE INDEX activity (activity_full))
这是我从txt文件中获取数据的新查询
"LOAD DATA LOCAL INFILE '$ptmpName'
INTO TABLE tbluser
LINES STARTING BY '{'
TERMINATED BY '\" />'
(@name,@activity_full,@activity,@class)
set
name=SUBSTRING_INDEX(@name,'\"',-1),
activity_full=SUBSTRING_INDEX(@name,'}',1),
activity=SUBSTRING_INDEX(activity_full,'/',-1),
class=SUBSTRING_INDEX(@name,'/',1)"