Note that there are some explanatory texts on larger screens.

plurals
  1. POChronic stale results using MySQLdb in Python
    primarykey
    data
    text
    <p>My Python program queries a set of tables in a MySQL DB, sleeps for 30 seconds, then queries them again, etc. The tables in question are continuously updated by a third-party, and (obviously) I would like to see the new results every 30 seconds.</p> <p>Let's say my query looks like this:</p> <pre><code>"select * from A where A.key &gt; %d" % maxValueOfKeyFromLastQuery </code></pre> <p>Regularly I will see that my program stops finding new results after one or two iterations, even though new rows <em>are</em> present in the tables. I know new rows are present in the tables because I can see them when I issue the identical query from interactive mysql (i.e. not from Python).</p> <p>I found that the problem goes away in Python if I terminate my connection to the database after each query and then establish a new one for the next query.</p> <p>I thought maybe this could be a server-side caching issue as discussed here: <a href="https://stackoverflow.com/questions/2474609/explicit-disable-mysql-query-cache-in-some-parts-of-program">Explicit disable MySQL query cache in some parts of program</a></p> <p>However:</p> <ol> <li><p>When I check the interactive mysql shell, it says that caching is on. (So if this is a caching problem, how come the interactive shell doesn't suffer from it?)</p></li> <li><p>If I explicitly execute <code>SET SESSION query_cache_type = OFF</code> from within my Python program, the problem still occurs.</p></li> </ol> <p>Creating a new DB connection for each query is the only way I've been able to make the problem go away.</p> <p>How can I get my queries from Python to see the new results that I know are there?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload