CREATE SCHEMA IF NOT EXISTS book; USE book; CREATE TABLE source_words( word VARCHAR(50) NOT NULL, INDEX(word) )ENGINE=MyISAM; LOAD DATA LOCAL INFILE ‘C:\\Users\\John\\Desktop\\source_words.txt‘ INTO TABLE source_words(word); SELECT COUNT(*) FROM SOURCE_WORDS; CREATE TABLE million_words( id INT UNSIGNED NOT NULL AUTO_INCREMENT, word VARCHAR(50) not null, primary key (id), UNIQUE INDEX (word)) ENGINE=INNODB; INSERT INTO million_words(word) SELECT DISTINCT word FROM source_words; INSERT INTO million_words(word) SELECT DISTINCT REVERSE(word) FROM source_words WHERE REVERSE(word) NOT IN (SELECT word FROM source_words); SELECT @cnt := COUNT(*) FROM million_words; --59572 SELECT @diff := 1000000- @cnt; --940428 SET @sql = CONCAT(" INSERT INTO million_words(word) SELECT DISTINCT CONCAT(word,‘X1Y‘) FROM source_words LIMIT",@diff); PREPARE cmd FROM @sql; EXECUTE cmd; SELECT COUNT(*) FROM million_words; --89358
测试数据链接:
http://effectivemysql.com/downloads/words
时间: 2024-11-05 18:49:27