I've a table Film:
CREATE TABLE film (
film_id NUMBER(5) NOT NULL,
title varchar2(255));
And I wanted to make the query, which counts how many titles start with the same word and only displays ones with more than 20, faster using a function based index. The query:
SELECT FW_SEPARATOR.FIRST_WORD AS "First Word", COUNT(FW_SEPARATOR.FIRST_WORD) AS "Count"
FROM (SELECT regexp_replace(FILM.TITLE, '(\w+).*$','\1') AS FIRST_WORD FROM FILM) FW_SEPARATOR
GROUP BY FW_SEPARATOR.FIRST_WORD
HAVING COUNT(FW_SEPARATOR.FIRST_WORD) >= 20;
The thing is, I created this function based index:
CREATE INDEX FIRST_WORD_INDEX ON FILM(regexp_replace(TITLE, '(\w+).*$','\1'));
But it didn't speed anything up...
I was wondering if anyone could help me with this :)
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
SELECT
FW_SEPARATOR.FIRST_WORD AS "First Word",
COUNT(FW_SEPARATOR.FIRST_WORD) AS "Count"
FROM
(SELECT
regexp_replace(FILM.TITLE,
'(\w+).*$',
'\1') AS FIRST_WORD
FROM
FILM
HAVING
(
COUNT(FIRST_WORD) >= 20
)) FW_SEPARATOR
GROUP BY
FW_SEPARATOR.FIRST_WORD
HAVING
COUNT(FW_SEPARATOR.FIRST_WORD) >= 20