DEV Community

Scale
Scale

Posted on

πŸ”„ GBase Database Explained: From Data Operations to Transaction Logging

At first glance, SQL operations like UPDATE and DELETE seem simple:

UPDATE users SET age = 30 WHERE id = 1;
Enter fullscreen mode Exit fullscreen mode

But inside GBase database, this triggers a much deeper process:

πŸ‘‰ A transaction begins
πŸ‘‰ Data is modified
πŸ‘‰ Logs record every change
πŸ‘‰ The system ensures consistency and recovery

This article connects data operations + transaction mechanisms into one complete picture.


✏️ Part 1: Data Operations in GBase

GBase supports standard SQL DML operations.

πŸ”„ UPDATE Example

UPDATE t_user 
SET f_age = 20 
WHERE f_userid = 1;
Enter fullscreen mode Exit fullscreen mode
  • Updates specific rows
  • Returns number of affected rows
  • Requires a WHERE clause for safety

Example output:

1 row(s) updated.
Enter fullscreen mode Exit fullscreen mode

πŸ—‘οΈ DELETE Example

DELETE FROM t_user 
WHERE f_userid = 1;
Enter fullscreen mode Exit fullscreen mode
  • Removes selected rows
  • Keeps table structure intact

Example output:

1 row(s) deleted.
Enter fullscreen mode Exit fullscreen mode

These behaviors follow standard SQL semantics in GBase. ([GBase][1])


🧠 Important: Every Operation is a Transaction

In GBase, every DML operation runs inside a transaction.

There are two modes:

1. Implicit Transactions (Default)

UPDATE users SET age = 30;
Enter fullscreen mode Exit fullscreen mode
  • Automatically starts
  • Automatically commits

2. Explicit Transactions

BEGIN;
UPDATE users SET age = 30 WHERE id = 1;
COMMIT;
Enter fullscreen mode Exit fullscreen mode

Or rollback:

ROLLBACK;
Enter fullscreen mode Exit fullscreen mode

This gives developers full control over execution. ([cnblogs.com][2])


🧱 Part 2: What Happens Internally?

Let’s break down an UPDATE:

UPDATE users SET age = 30 WHERE id = 1;
Enter fullscreen mode Exit fullscreen mode

Internal Workflow:

  1. Transaction begins
  2. Original data is read
  3. Change is applied
  4. Log entry is written
  5. Transaction commits

πŸ‘‰ Nothing is changed β€œsilently”—everything is tracked.


πŸ“Š Part 3: Logging β€” The Backbone of Reliability

GBase uses logical logs to record transactions.

You can inspect logs with:

onstat -l
Enter fullscreen mode Exit fullscreen mode

Example Output:

numrecs    Log Space used
82067      12130972
Enter fullscreen mode Exit fullscreen mode

This shows:

  • Number of operations recorded
  • Total log space usage ([GBase][3])

πŸ”„ Log Switching

When logs are full, GBase performs log switching:

onmode -l
Enter fullscreen mode Exit fullscreen mode

After switching:

  • Old log β†’ archived or reused
  • New log β†’ becomes active

Example:

πŸ‘‰ Log ID changes (e.g., 18 β†’ 19) ([GBase][3])


⚠️ Why Logging is Critical

1. Crash Recovery

If the system crashes:

  • Logs are replayed
  • Committed transactions are restored

2. Rollback Support

ROLLBACK;
Enter fullscreen mode Exit fullscreen mode
  • Undoes uncommitted changes
  • Uses log history

3. Data Consistency

Logs ensure:

  • No partial updates
  • No corrupted data

πŸ”¬ Real Example: UPDATE + Logging

UPDATE t_employee 
SET f_employeename = 'employee_updated' 
WHERE f_employeeid = 11;
Enter fullscreen mode Exit fullscreen mode

After execution:

  • Row is updated
  • Log entry is created
  • Timestamp recorded

This proves that every change is tracked. ([GBase][3])


⚑ Performance Impact of Data Operations

Large operations can heavily affect logs.

Example:

UPDATE orders SET status = 'done';
Enter fullscreen mode Exit fullscreen mode

Impact:

  • Thousands of log entries
  • Increased disk I/O
  • Possible slowdown

Optimization Tips:

βœ… Use batch updates
βœ… Avoid full-table operations
βœ… Monitor logs regularly


πŸ› οΈ Monitoring Transactions

GBase provides tools for real-time inspection.

Check Logs

onstat -l
Enter fullscreen mode Exit fullscreen mode

Check Transactions

onstat -x
Enter fullscreen mode Exit fullscreen mode

Shows:

  • Active transactions
  • Commit/rollback status ([GBase][4])

Check Performance

onstat -p
Enter fullscreen mode Exit fullscreen mode

Displays:

  • Reads/writes
  • Buffer usage
  • System activity ([GBase][4])

🧠 Key Insight

In GBase:

Layer Role
SQL Defines data changes
Transaction Controls execution
Logging Records everything

πŸ‘‰ These three layers work together to guarantee reliability.


πŸš€ Final Thoughts

GBase turns simple SQL into a fully managed, recoverable process.

Instead of thinking:

❓ β€œI updated a row”

You should think:

βœ… β€œI executed a transaction that was logged, validated, and committed safely”

Top comments (0)