1
by brian
clean slate |
1 |
DROP TABLE IF EXISTS t1, t2;
|
2 |
CREATE TABLE t1 (
|
|
3 |
id mediumint unsigned NOT NULL auto_increment,
|
|
4 |
tag char(6) NOT NULL default '',
|
|
5 |
value text NOT NULL default '',
|
|
6 |
PRIMARY KEY (id),
|
|
7 |
KEY kt(tag),
|
|
8 |
KEY kv(value(15)),
|
|
9 |
FULLTEXT KEY kvf(value)
|
|
10 |
) ENGINE=MyISAM;
|
|
11 |
Warnings:
|
|
12 |
Warning 1101 BLOB/TEXT column 'value' can't have a default value
|
|
13 |
CREATE TABLE t2 (
|
|
14 |
id_t2 mediumint unsigned NOT NULL default '0',
|
|
15 |
id_t1 mediumint unsigned NOT NULL default '0',
|
|
16 |
field_number tinyint unsigned NOT NULL default '0',
|
|
17 |
PRIMARY KEY (id_t2,id_t1,field_number),
|
|
18 |
KEY id_t1(id_t1)
|
|
19 |
) ENGINE=MyISAM;
|
|
20 |
INSERT INTO t1 (tag,value) VALUES ('foo123','bar111');
|
|
21 |
INSERT INTO t1 (tag,value) VALUES ('foo123','bar222');
|
|
22 |
INSERT INTO t1 (tag,value) VALUES ('bar345','baz333 ar');
|
|
23 |
INSERT INTO t2 VALUES (2231626,64280,0);
|
|
24 |
INSERT INTO t2 VALUES (2231626,64281,0);
|
|
25 |
INSERT INTO t2 VALUES (12346, 3, 1);
|
|
26 |
SELECT * FROM t1;
|
|
27 |
id tag value
|
|
28 |
1 foo123 bar111
|
|
29 |
2 foo123 bar222
|
|
30 |
3 bar345 baz333 ar
|
|
31 |
SELECT * FROM t2;
|
|
32 |
id_t2 id_t1 field_number
|
|
33 |
12346 3 1
|
|
34 |
2231626 64280 0
|
|
35 |
2231626 64281 0
|
|
36 |
SELECT DISTINCT t2.id_t2 FROM t2, t1
|
|
37 |
WHERE MATCH (t1.value) AGAINST ('baz333') AND t1.id = t2.id_t1;
|
|
38 |
id_t2
|
|
39 |
12346
|
|
40 |
SELECT DISTINCT t2.id_t2 FROM t2, t1
|
|
41 |
WHERE MATCH (t1.value) AGAINST ('baz333' IN BOOLEAN MODE)
|
|
42 |
AND t1.id = t2.id_t1;
|
|
43 |
id_t2
|
|
44 |
12346
|
|
45 |
DROP TABLE t1, t2;
|