Show a tables FULLTEXT indexed columns
Asked Answered
D

4

12

I'm looking to run a query that will return a list of columns in a table that are FULLTEXT indexed. The table is in MyISAM format and i'll be using php to construct the query.

Ideally i would run the query and it would return the information so i could construct a comma separated string of the columns.

e.g. "first_name, last_name, email"

Is this possible in MySQL?

Domenech answered 5/11, 2010 at 15:53 Comment(0)
S
28

You can get that information from the information_schema.STATISTICS table.

I'll give you the query to get all columns in the table that are in one or more FULLTEXT indexes, since I think that's what you are asking for. Bear in mind that the specific combinations of columns in each FULLTEXT index are very important. MySQL can't use a FULLTEXT index to search multiple columns unless there is a single FULLTEXT index that includes all of those column.

Here's the first query that gives the output you asked for:

select group_concat(distinct column_name)
from information_schema.STATISTICS 
where table_schema = 'your_db' 
and table_name = 'your_table' 
and index_type = 'FULLTEXT';

And here's one that shows the various combinations of columns in FULLTEXT indexe if there is more than 1 on the table:

select index_name, group_concat(column_name) as columns
from information_Schema.STATISTICS 
where table_schema = 'your_db' 
and table_name = 'your_table' 
and index_type = 'FULLTEXT'
group by index_name;
Snailpaced answered 5/11, 2010 at 16:16 Comment(0)
P
1

Here's another way:

SHOW CREATE TABLE [database_name].[table_name]

Replace the bracketed placeholders with your own values.

Peruse the output for FULLTEXT lines.

Peafowl answered 13/11, 2016 at 20:42 Comment(0)
A
1

I am too late but here it is.

In case you don't remember the table names which you've indexed to, you can get their table and schema names from the information_schema database.

All you need to do is -

select table_name from information_schema.STATISTICS  where table_schema = 'your_schema_name'  and index_type = 'FULLTEXT';

The above code will give you only the names of all tables which contains full-text indexing.

select table_name,table_schema from information_schema.STATISTICS  where index_type = 'FULLTEXT';

However, this will give you database name as well as the table name which have full text indexing

Hope this helps!

Aright answered 29/8, 2022 at 14:0 Comment(0)
O
0

I'm just going to drop what worked for me.

SHOW CREATE TABLE `db_name`.`table_name`;

Ensure that the db_name and table_name are in separate backticks joined together by a dot(.).

Odd answered 27/5 at 1:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.