feat: add explain mysql

main
sudo pacman -Syu 2023-04-17 17:14:54 +07:00
parent 5e4a593acf
commit 9b5fceacaf
2 changed files with 30 additions and 0 deletions

View File

@ -131,6 +131,23 @@
<pre><span class="pl-k">CREATE</span> <span class="pl-k">INDEX</span> `<span class="pl-en">idx_timestamp</span>`
<span class="pl-k">ON</span> <span class="pl-s"><span class="pl-pds">`</span>user_upload<span class="pl-pds">`</span></span> (<span class="pl-s"><span class="pl-pds">`</span>timestamp<span class="pl-pds">`</span></span>);</pre>
</div>
<p>Use <code>EXPLAIN</code> to check if index is used or not:</p>
<ul>
<li>
<a
href="https://dev.mysql.com/doc/refman/5.7/en/explain-output.html"
rel="nofollow"
>For MySQL 5.7</a
>
</li>
<li>
<a
href="https://dev.mysql.com/doc/refman/8.0/en/explain-output.html"
rel="nofollow"
>For MySQL 8.0</a
>
</li>
</ul>
<h2>
<a
id="user-content-be-careful-with-null"
@ -273,6 +290,13 @@
>My Notes on GitLab Postgres Schema Design</a
>
</li>
<li>
<a
href="https://planetscale.com/blog/how-read-mysql-explains"
rel="nofollow"
>How to read MySQL EXPLAINs</a
>
</li>
</ul>
<div>

View File

@ -53,6 +53,11 @@ CREATE INDEX `idx_timestamp`
ON `user_upload` (`timestamp`);
```
Use `EXPLAIN` to check if index is used or not:
- [For MySQL 5.7](https://dev.mysql.com/doc/refman/5.7/en/explain-output.html)
- [For MySQL 8.0](https://dev.mysql.com/doc/refman/8.0/en/explain-output.html)
## Be careful with NULL
If compare with field which can be NULL, remember to check NULL for safety.
@ -97,3 +102,4 @@ Plase read docs about online ddl operations before do anything online (keep data
- [Things You Should Know About Databases](https://architecturenotes.co/things-you-should-know-about-databases/)
- [When to use JSON data type in database schema design?](https://shekhargulati.com/2022/01/08/when-to-use-json-data-type-in-database-schema-design/)
- [My Notes on GitLab Postgres Schema Design](https://shekhargulati.com/2022/07/08/my-notes-on-gitlabs-postgres-schema-design/)
- [How to read MySQL EXPLAINs](https://planetscale.com/blog/how-read-mysql-explains)