I have created a connection to Cloud SQL and used EXTERNAL_QUERY()
to export the data to Bigquery. My problem is that I do not know a computationally efficient way to export a new days data since the Cloud SQL table is not partitioned; however, it does have a date column date_field
but it is of the datatype char
.
I have tried running the following query with the view of scheduling a similar type so that it inserts the results:
SELECT * FROM EXTERNAL_QUERY("connection", "SELECT period FROM table where date_field = cast(current_date() as char);")
but it takes very long to run, whereas:
SELECT * FROM EXTERNAL_QUERY("connection", "SELECT period FROM table where date_field = '2020-03-20';")
is almost instant.
Firstly, it’s highly recommended to convert the ‘date_field’ column to the datatype DATE. This would improve simplicity and performance in the future.
When comparing two strings, MySQL will make use of indexes to speed up the queries. This is executed successfully when defining the string as ‘2020-03-20’ for example. When casting the current date to a string, it’s possible that the characters set used in the comparison aren’t the same, so indexes can’t be used.
You may want to check the characters set once current_datetime has been casted compared to the values in the ‘date_field’ column. You could then use this command instead of cast: CONVERT(current_date() USING enter_char_sets_here)
Here is the documentation for the different casting functions.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments