I noticed the following: I'm creating a view for a table where some columns contain csv
values. I want to split those csv files on the fly and make them individual columns in the view.
As a start, I simply created a function that returns the input value itself:
CREATE FUNCTION `split`(`csv` TEXT, `pos` INT)
RETURNS varchar(255) CHARSET utf8
return csv
Now the interesting part: as soon as I make use of the split
function in my CREATE VIEW AS SELECT split(mytable.csv, 3) as split FROM mytable
table, the execution time of SELECT
queries is doubled (even though I simply return the value itself so far!).
Isn't that strange? Or is this supposed to work like that, as mysql cannot optimized queries when using functions?
Lateron I want to replace the function as follows. But that does not matter for the main question part:
CREATE FUNCTION split(csv TEXT, pos INT)
RETURNS varchar(255) CHARSET utf8
return substring_index(substring_index(csv, ',', pos), ',', -1)
Then a split('my,example,split,string', 2)
would extract "example".