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

The current SQL query that checks table existence is under optimized on big database #1439

Closed
wants to merge 1 commit into from

Conversation

essobedo
Copy link

break;
default:
// the MySQL-style LIMIT clause
query = "SELECT count(*) from (SELECT 1 FROM " + tableName + " LIMIT 1) T";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just: SELECT 1 FROM tableNAME LIMIT 1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll answer myself: because if the table is empty it would not work, however if the table doesn't exist it would throw a SQL Exception

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's the expected behavior. If the table is empty or pre-filled it will return true, if the table doesn't exist an SQLException will be thrown, the exception will be caught to return false

@tristantarrant
Copy link
Member

Testing

@tristantarrant
Copy link
Member

Pulled, thanks

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

Successfully merging this pull request may close these issues.

2 participants