I need to generate large amount of rows in one table, unfortunately, one column needs to be generated on the app side (PHP).
So essentially I need to generate something like this:
id | encoded_val_based_on_id
-------------------------------
1 | my_encode_func( 1 )
-------------------------------
2 | my_encode_func( 2 )
-------------------------------
3 | my_encode_func( 3 )
-------------------------------
4 | my_encode_func( 4 )
I assume, that there must be better way then generating N
queries to get N
ids and then update these records back with "encoded_val_based_on_id".
Besides that, I'd like to keep the unique index on the "encoded_val_based_on_id", which I'd be unable to do as I'd generate blank rows and then fill them up.
I could lock the table, get the last ID, generate IDs by incrementing in my app + generate all other things, insert them and unlock table. I don't think it's the right way, but at least it can be done in just 1 query (batch insert) and I can keep the unique index there.