Hi, I have a stored procedure that gets called from a loop and inside it executes SCALAR three times in each iteration for something similar to this:
num_of_ids = SCALAR(CONCAT('SELECT COUNT(1) FROM test_table WHERE test_id=', v_test_id), QUERY(a INT));
The whole procedure takes a lot of time because it handles a large amount of data, but I’ve encountered many blogs where people talk how Scalar UDFs in general lower performance significantly because query optimisation does not work on them, as well as some other reasons that I do not fully understand yet
Though the most of the blogs I’ve read this on are related to SQL Server, I’m starting to doubt my use of Scalar and if that is the case with SingleStore engine as well. Any information is welcome, as well as if this can be improved in some other way.
I’m stumbling in the dark a bit, but in some blogs they said that instead of SCALAR you should use TVFs. I’ve created the TVFs, but I’m still not sure how to use them inside the stored procedure since SELECT is not allowed…
Thanks!