-
[MySql] Transaction Isolation level
1. Intro When dealing with atomic operations in databases, it’s essential to use transactions effectively. However, simply processing transactions in a First-In-First-Out (FIFO) order can lead to serious logical inconsistencies. Imagine a scenario where Transaction A interrupts and updates data that Transaction B has already read and is relying on. Or consider a case where…
-
[Go & MySQL] parseTime option
Intro When working with MySQL databases in Go, handling DATE, DATETIME, and TIMESTAMP fields can sometimes lead to confusion, especially when dealing with time parsing. By default, Go’s MySQL driver treats date and time fields as []uint8 (byte slices) unless explicitly configured to handle them as time.Time. This behavior can cause issues if you’re expecting…
-
[Mysql] ID jumps when using UPSERT
You might have noticed that the PRIMARY KEY ID jumps even when no new record is inserted. This behavior commonly occurs when using the UPSERT operation. In MySQL, where the ID column is set to AUTO_INCREMENT, the increment key is consumed whenever you perform an UPSERT (INSERT … ON DUPLICATE KEY UPDATE). This happens because…
-
[Go] How to deal with sort and heap (2)
1. Quick Recap In the previous post, we explored the concept of interfaces and how the sort package utilizes them. Understanding the abstract role that interfaces play, independent of specific implementations, was crucial. This abstraction allowed us to work with various types by tying them to the same interface, enabling them to be passed as…
-
[basic CS] Understanding 2’s complement
1. Computer is not smart In the era of Artificial Intelligence, we often treat computers like magical wands. Thanks to AI, we can effortlessly generate images and retrieve information through tools like ChatGPT. While these capabilities might seem like magic, at their core, they are driven by the principles of a simple calculator. Let’s delve…
-
[Go] How to deal with sort and heap (1)
1. Understanding Interface 1-a. What is an interface Before we take a look at sort and heap packages, we have to understand what Interface is and how it works. We use Interface to maintain flexible code. Instead of relying on concrete implementations, interfaces allow you to work with abstract method sets, enabling you to apply…