Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent "LOCK TABLES" in qa_db_word_mapto_ids_add($words) #813

Open
q2apro opened this issue May 11, 2020 · 0 comments
Open

Prevent "LOCK TABLES" in qa_db_word_mapto_ids_add($words) #813

q2apro opened this issue May 11, 2020 · 0 comments

Comments

@q2apro
Copy link

q2apro commented May 11, 2020

I am still wondering why some of my heavy visited website requests take a while, one of the culprits is the indexing, which I need to accept as necessary. But now I stumbled over https://github.com/q2a/question2answer/blob/dev/qa-include/db/post-create.php#L249

qa_db_query_sub('LOCK TABLES ^words WRITE'); // to prevent two requests adding the same word

From my understanding, the entire db table gets locked until it is unlocked again. So no other queries can take place.

Shouldn't a LOCK be avoided regarding performance issues and other problems?

See also https://stackoverflow.com/q/6621303/1066234


And the LOCK seems also to lock the constraint tables (titlewords, contentwords, tagwords, posttags):

If you lock a table explicitly with LOCK TABLES, any tables related by a foreign key constraint are opened and locked implicitly. For foreign key checks, a shared read-only lock (LOCK TABLES READ) is taken on related tables. For cascading updates, a shared-nothing write lock (LOCK TABLES WRITE) is taken on related tables that are involved in the operation.

https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html


Probably the insert of missing words can be put into one single MYSQL query, see examples at:
https://stackoverflow.com/a/6621549/1066234
https://stackoverflow.com/a/6621547/1066234

INSERT INTO loggingtable (url) SELECT url FROM tablewithurls u LEFT JOIN loggingtable l ON l.url=t.url WHERE {some criterion used to pick the url to work on} AND l.url IS NULL

Probably helpful too: "MySQL: Insert record if not exists in table" https://stackoverflow.com/q/3164505/1066234

@q2apro q2apro changed the title Prevent "LOCK TABLES" found in qa_db_word_mapto_ids_add($words)? Prevent "LOCK TABLES" found in qa_db_word_mapto_ids_add($words) May 11, 2020
@q2apro q2apro changed the title Prevent "LOCK TABLES" found in qa_db_word_mapto_ids_add($words) Prevent "LOCK TABLES" in qa_db_word_mapto_ids_add($words) May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant