It looks like I lack some basic understanding of how SQL databases work, specifically MySQL. (Edit: for now I am using the InnoDB engine.) I have a thread in a program written in pure Groovy (no Grails) that does CREATE TABLE
using groovy.sql.Sql
, which is supposed to be a wrapper around JDBC
. My question is, after this call returns, can I immediately access this table from another thread, or does it depend on luck? Do I have to call e.g. sql.close()
or do I have to access the table from the creating thread first, as then logically it will have to be created?
I know that, for example, if I have a transaction, then the statement may not have an effect immediately... or so I think. Even if I don't create a transaction explicitly, who knows if Groovy or JDBC will create one for me. If I am using Hibernate or some other framework, it can also do whatever it considers optimal. My impression is that even sqlalchemy
in python may do some optimization of this kind, unless I tell it not to. Similarly, what if MySQL itself is somehow caching my statement for future execution, for performance optimization, and not executing it right away?
Are there any formal rules or principles such as ACID that allow me to have some certainty? How do I know when a SQL statement is done so I can use its result? Same applies to other languages and database types, of course.