Skip to content

refactor: quick cap on SQL print max length - #23229

Merged
7 commits merged into
matrixorigin:3.0-devfrom
XuPeng-SH:optimize-logging-2
Dec 7, 2025
Merged

7 commits merged into
matrixorigin:3.0-devfrom
XuPeng-SH:optimize-logging-2

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Dec 7, 2025 •

Copy link
Copy Markdown
Contributor

User description

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #23222

What this PR does / why we need it:

quick cap on SQL print max length


PR Type

Enhancement, Bug fix


Description

  • Centralize byte and string utility functions into common package

    • Create CloneBytes, CloneBytesIf, and Abbreviate utilities
    • Remove duplicate implementations across codebase
  • Limit SQL logging output to 500 characters maximum

    • Prevent excessive log sizes from long SQL statements
    • Apply abbreviation consistently across logging calls
  • Optimize byte operations and comparisons

    • Replace manual byte copying with vector's CloneBytesAt method
    • Use bytes.Compare for direct byte slice comparison
  • Remove unused utility functions and code

    • Delete Timeout struct and related methods
    • Remove redundant Min function (use built-in min)

Diagram Walkthrough

flowchart LR
  A["Duplicate byte/string utilities<br/>across multiple files"] -->|Consolidate| B["pkg/common/util<br/>bytes.go & string.go"]
  C["Long SQL statements<br/>in logs"] -->|Apply Abbreviate| D["Truncated output<br/>max 500 chars"]
  E["Manual byte copying<br/>copyBytes functions"] -->|Replace with| F["Vector.CloneBytesAt<br/>& CloneBytes"]
  B -->|Import & use| G["Updated files:<br/>cdc, frontend, sql"]
Loading

File Walkthrough

Relevant files
Enhancement
17 files
bytes.go
New byte cloning utility functions                                             
+41/-0   
string.go
New string abbreviation utility function                                 
+38/-0   
table_scanner.go
Limit SQL logging to 500 characters                                           
+2/-1     
util.go
Replace copyBytes with vector.CloneBytesAt                             
+2/-12   
data_branch.go
Optimize byte comparison and remove copyBytes                       
+7/-6     
mysql_buffer.go
Replace Min function with built-in min                                     
+1/-1     
mysql_cmd_executor.go
Replace SubStringFromBegin with Abbreviate                             
+5/-4     
mysql_protocol_test.go
Replace Min function with built-in min                                     
+1/-1     
output.go
Replace copyBytes with CloneBytesIf utility                           
+7/-6     
util.go
Remove duplicate utilities and use common package               
+2/-87   
compile.go
Limit SQL logging to 500 characters                                           
+2/-1     
compile2.go
Limit SQL logging to 500 characters                                           
+11/-3   
ddl.go
Limit SQL logging to 500 characters                                           
+2/-1     
scope.go
Limit SQL logging to 500 characters                                           
+3/-2     
sql_executor.go
Limit SQL logging to 500 characters                                           
+3/-6     
func_mo.go
Limit SQL logging to 500 characters                                           
+2/-1     
txn_table.go
Limit SQL logging to 500 characters                                           
+1/-1     
Tests
4 files
bytes_test.go
Tests for byte cloning utilities                                                 
+88/-0   
string_test.go
Tests for string abbreviation function                                     
+53/-0   
util_test.go
Update test to use commonutil.CloneBytes                                 
+2/-1     
util_test.go
Update tests for removed and moved utilities                         
+3/-15   
Bug fix
1 files
server_query.go
Replace copyBytes with commonutil.CloneBytes                         
+5/-9     

@qodo-code-review

qodo-code-review Bot commented Dec 7, 2025 •

Copy link
Copy Markdown

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
⚪
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
⚪
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

⚪
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
Audit context: New logging truncates SQL text via commonutil.Abbreviate(..., 500) which may remove
actionable detail from audit trails unless the full SQL is recorded elsewhere.

Referred Code
		if bat != nil {
			bat.Clean(exec.s.mp)
		}
	}
	return executor.Result{}, err
}

if !statementOption.DisableLog() {
	logutil.Info("sql_executor exec",
		zap.String("sql", commonutil.Abbreviate(sql, 500)),
		zap.String("txn-id", hex.EncodeToString(exec.opts.Txn().Txn().ID)),

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status:
Sensitive logging: The code logs SQL statements (now truncated) which could still include sensitive data;
verify upstream scrubbing or parameterization to prevent PII/secret exposure in logs.

Referred Code
// statistical information record and trace.
compileStart := time.Now()
_, task := gotrace.NewTask(context.TODO(), "pipeline.Compile")
defer func() {
	if e := recover(); e != nil {
		err = moerr.ConvertPanicError(execTopContext, e)
		c.proc.Error(execTopContext, "panic in compile",
			zap.String("sql", commonutil.Abbreviate(c.sql, 500)),
			zap.String("error", err.Error()))
	}

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review

qodo-code-review Bot commented Dec 7, 2025 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
✅ Fix incorrect return and type mismatches
Suggestion Impact:The commit changed PreparedTS and CommitTS to use src.GetPreparedTS() and src.GetCommitTS() instead of cloning bytes, and removed the incorrect early return, returning dst instead—matching the suggested fixes.

code diff:

-		PreparedTS: commonUtil.CloneBytes(src.GetPreparedTS()),
-		CommitTS:   commonUtil.CloneBytes(src.GetCommitTS()),
+		PreparedTS: src.GetPreparedTS(),
+		CommitTS:   src.GetCommitTS(),
 		Mode:       src.GetMode(),
 		Isolation:  src.GetIsolation(),
 	}
-	return commonUtil.CloneBytes(src.GetID())
 	return dst

Fix the copyTxnMeta function by removing an erroneous early return statement and
correcting the type-mismatched assignments for the PreparedTS and CommitTS
fields.

pkg/cnservice/server_query.go [349-361]

 func copyTxnMeta(src txn.TxnMeta) *txn.TxnMeta {
 	dst := &txn.TxnMeta{
 		ID:         commonUtil.CloneBytes(src.GetID()),
 		Status:     src.GetStatus(),
 		SnapshotTS: src.GetSnapshotTS(),
-		PreparedTS: commonUtil.CloneBytes(src.GetPreparedTS()),
-		CommitTS:   commonUtil.CloneBytes(src.GetCommitTS()),
+		PreparedTS: src.GetPreparedTS(),
+		CommitTS:   src.GetCommitTS(),
 		Mode:       src.GetMode(),
 		Isolation:  src.GetIsolation(),
 	}
-	return commonUtil.CloneBytes(src.GetID())
 	return dst
 }

[Suggestion processed]

Suggestion importance[1-10]: 10

__

Why: The suggestion correctly identifies two critical bugs introduced by the PR: an incorrect return statement that returns the wrong type, and a type mismatch that would cause a compilation error.

High
Prevent data corruption by cloning slice

To prevent potential data corruption in compareSingleValInVector, clone the byte
slice from the vector using vec.CloneBytesAt before passing it to
types.DecodeJson, as DecodeJson may modify the slice in-place.

pkg/frontend/data_branch.go [4397-4400]

 	case types.T_json:
-		val1 := types.DecodeJson(vec1.GetBytesAt(rowIdx1))
-		val2 := types.DecodeJson(vec2.GetBytesAt(rowIdx2))
+		val1 := types.DecodeJson(vec1.CloneBytesAt(rowIdx1))
+		val2 := types.DecodeJson(vec2.CloneBytesAt(rowIdx2))
 		return bytejson.CompareByteJson(val1, val2), nil
  • Apply / Chat
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a potential data corruption bug where types.DecodeJson might modify a byte slice that shares memory with a vector's underlying data, and proposes a correct fix by cloning the slice.

High
  • Update

@ghost
ghost merged commit deab3d9 into matrixorigin:3.0-dev Dec 7, 2025
XuPeng-SH added a commit to XuPeng-SH/matrixone that referenced this pull request Dec 7, 2025
- [ ] API-change
- [ ] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [x] Code Refactoring

issue matrixorigin#23222

quick cap on SQL print max length

___

Enhancement, Bug fix

___

- Centralize byte and string utility functions into common package
  - Create `CloneBytes`, `CloneBytesIf`, and `Abbreviate` utilities
  - Remove duplicate implementations across codebase

- Limit SQL logging output to 500 characters maximum
  - Prevent excessive log sizes from long SQL statements
  - Apply abbreviation consistently across logging calls

- Optimize byte operations and comparisons
  - Replace manual byte copying with vector's `CloneBytesAt` method
  - Use `bytes.Compare` for direct byte slice comparison

- Remove unused utility functions and code
  - Delete `Timeout` struct and related methods
  - Remove redundant `Min` function (use built-in `min`)

___

```mermaid
flowchart LR
  A["Duplicate byte/string utilities<br/>across multiple files"] -->|Consolidate| B["pkg/common/util<br/>bytes.go & string.go"]
  C["Long SQL statements<br/>in logs"] -->|Apply Abbreviate| D["Truncated output<br/>max 500 chars"]
  E["Manual byte copying<br/>copyBytes functions"] -->|Replace with| F["Vector.CloneBytesAt<br/>& CloneBytes"]
  B -->|Import & use| G["Updated files:<br/>cdc, frontend, sql"]
```

<details> <summary><h3> File Walkthrough</h3></summary>

<table><thead><tr><th></th><th align="left">Relevant
files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><details><summary>17
files</summary><table>
<tr>
<td><strong>bytes.go</strong><dd><code>New byte cloning utility
functions</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-0cd1ad6aa08bd7e47f08ca6841fdedaea22fac08d8b84ccaf263f7a39fdb932c">+41/-0</a>&nbsp;
&nbsp; </td>

</tr>

<tr>
<td><strong>string.go</strong><dd><code>New string abbreviation utility
function</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
</dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-1ede190a8918c9653055ee53088626775f70eb9c62c574288aa5b82199f6bc3b">+38/-0</a>&nbsp;
&nbsp; </td>

</tr>

<tr>
<td><strong>table_scanner.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-ff43b62d0f42085266c063c203474532c19fb2aeb3e6d390b187f63f5306af8b">+2/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>util.go</strong><dd><code>Replace copyBytes with
vector.CloneBytesAt</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
</dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-46b260aa5fed62ad704662ba98a550547b13b1950d693dac8d96a865e1e41237">+2/-12</a>&nbsp;
&nbsp; </td>

</tr>

<tr>
<td><strong>data_branch.go</strong><dd><code>Optimize byte comparison
and remove copyBytes</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-632e0d2d46c8bdef4144b4d6f532cf8df78cc583e4903672ae6675d8c09783b4">+7/-6</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>mysql_buffer.go</strong><dd><code>Replace Min function with
built-in min</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-57df9142267c7468f8fc339e9071fe9750d24b5a6ab2efbca5d0a2765ff5ca59">+1/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>mysql_cmd_executor.go</strong><dd><code>Replace
SubStringFromBegin with Abbreviate</code>&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-af2611d5fc89704398fe09d09644efa41fec8931b395eda292f2f474f1216275">+5/-4</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>mysql_protocol_test.go</strong><dd><code>Replace Min
function with built-in min</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-e6b33be301283d85ec5e07d87fa0d6d826a68d7810019b613d315659f329ebac">+1/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>output.go</strong><dd><code>Replace copyBytes with
CloneBytesIf utility</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-df1b62301c885e4cd4075140bdd989df1c9660b561033f8b56a56b605f5e7d18">+7/-6</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>util.go</strong><dd><code>Remove duplicate utilities and use
common package</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-005617216374ac58bf3cf72b81841d5cb6a17495d1d7b36ff387e294a0d6e043">+2/-87</a>&nbsp;
&nbsp; </td>

</tr>

<tr>
<td><strong>compile.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-1f95b23a5c61734c0686b47c14583f114fe66c015310f43992c517fa62c76f3d">+2/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>compile2.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-1c117d6b04a95023864b6b925099524a28e4ce3e4c8b6d93f4ab32d62cd4974e">+11/-3</a>&nbsp;
&nbsp; </td>

</tr>

<tr>
<td><strong>ddl.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-819bfdf891fa506cb2b4c89006896d528675fd554c341f38d1a1bf14a496c8aa">+2/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>scope.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-1a84d311b058e390f8c70e84f5e0c59dbd42736a85d022e2a283d926d43f5bd6">+3/-2</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>sql_executor.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-8d93841d90b6b267a1c218f24e1f564febdcc4dd780d04909033d706302ca215">+3/-6</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>func_mo.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-b553fa8d20dd9d505e58e3272ad74d359a50ce56152e523c8886ef1316b14ed9">+2/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>txn_table.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-ec8d7fbb6765aa12484ff5529b88835dc1da369005256b065fb3db4972f2d32f">+1/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

</table></details></td></tr><tr><td><strong>Tests</strong></td><td><details><summary>4
files</summary><table>
<tr>
<td><strong>bytes_test.go</strong><dd><code>Tests for byte cloning
utilities</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-e0ee223e0dd8dbd06e10644be0d576d23f205e905a06cc3af94ce49585985a3b">+88/-0</a>&nbsp;
&nbsp; </td>

</tr>

<tr>
<td><strong>string_test.go</strong><dd><code>Tests for string
abbreviation function</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-266b890c079978ce53248b043bfdeef28ac0e94d97dc24715d420637326f295a">+53/-0</a>&nbsp;
&nbsp; </td>

</tr>

<tr>
<td><strong>util_test.go</strong><dd><code>Update test to use
commonutil.CloneBytes</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-682a3d8cc46973e1c1726fa8a8ece492f2a8aba302fb81cee8578934c29caea6">+2/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>util_test.go</strong><dd><code>Update tests for removed and
moved utilities</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-f51b6d5837418f5bbf801345e25b4bfcc4cd436bdec4534ab7a8aa8dc01839e0">+3/-15</a>&nbsp;
&nbsp; </td>

</tr>
</table></details></td></tr><tr><td><strong>Bug
fix</strong></td><td><details><summary>1 files</summary><table>
<tr>
<td><strong>server_query.go</strong><dd><code>Replace copyBytes with
commonutil.CloneBytes</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-9155e9743825e69f57408c43feab229fd722006804cef7dffbf57a78d507d7c1">+5/-9</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>
</table></details></td></tr></tr></tbody></table>

</details>

___
XuPeng-SH added a commit to XuPeng-SH/matrixone that referenced this pull request Dec 8, 2025
- [ ] API-change
- [ ] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [x] Code Refactoring

issue matrixorigin#23222

quick cap on SQL print max length

___

Enhancement, Bug fix

___

- Centralize byte and string utility functions into common package
  - Create `CloneBytes`, `CloneBytesIf`, and `Abbreviate` utilities
  - Remove duplicate implementations across codebase

- Limit SQL logging output to 500 characters maximum
  - Prevent excessive log sizes from long SQL statements
  - Apply abbreviation consistently across logging calls

- Optimize byte operations and comparisons
  - Replace manual byte copying with vector's `CloneBytesAt` method
  - Use `bytes.Compare` for direct byte slice comparison

- Remove unused utility functions and code
  - Delete `Timeout` struct and related methods
  - Remove redundant `Min` function (use built-in `min`)

___

```mermaid
flowchart LR
  A["Duplicate byte/string utilities<br/>across multiple files"] -->|Consolidate| B["pkg/common/util<br/>bytes.go & string.go"]
  C["Long SQL statements<br/>in logs"] -->|Apply Abbreviate| D["Truncated output<br/>max 500 chars"]
  E["Manual byte copying<br/>copyBytes functions"] -->|Replace with| F["Vector.CloneBytesAt<br/>& CloneBytes"]
  B -->|Import & use| G["Updated files:<br/>cdc, frontend, sql"]
```

<details> <summary><h3> File Walkthrough</h3></summary>

<table><thead><tr><th></th><th align="left">Relevant
files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><details><summary>17
files</summary><table>
<tr>
<td><strong>bytes.go</strong><dd><code>New byte cloning utility
functions</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-0cd1ad6aa08bd7e47f08ca6841fdedaea22fac08d8b84ccaf263f7a39fdb932c">+41/-0</a>&nbsp;
&nbsp; </td>

</tr>

<tr>
<td><strong>string.go</strong><dd><code>New string abbreviation utility
function</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
</dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-1ede190a8918c9653055ee53088626775f70eb9c62c574288aa5b82199f6bc3b">+38/-0</a>&nbsp;
&nbsp; </td>

</tr>

<tr>
<td><strong>table_scanner.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-ff43b62d0f42085266c063c203474532c19fb2aeb3e6d390b187f63f5306af8b">+2/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>util.go</strong><dd><code>Replace copyBytes with
vector.CloneBytesAt</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
</dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-46b260aa5fed62ad704662ba98a550547b13b1950d693dac8d96a865e1e41237">+2/-12</a>&nbsp;
&nbsp; </td>

</tr>

<tr>
<td><strong>data_branch.go</strong><dd><code>Optimize byte comparison
and remove copyBytes</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-632e0d2d46c8bdef4144b4d6f532cf8df78cc583e4903672ae6675d8c09783b4">+7/-6</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>mysql_buffer.go</strong><dd><code>Replace Min function with
built-in min</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-57df9142267c7468f8fc339e9071fe9750d24b5a6ab2efbca5d0a2765ff5ca59">+1/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>mysql_cmd_executor.go</strong><dd><code>Replace
SubStringFromBegin with Abbreviate</code>&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-af2611d5fc89704398fe09d09644efa41fec8931b395eda292f2f474f1216275">+5/-4</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>mysql_protocol_test.go</strong><dd><code>Replace Min
function with built-in min</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-e6b33be301283d85ec5e07d87fa0d6d826a68d7810019b613d315659f329ebac">+1/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>output.go</strong><dd><code>Replace copyBytes with
CloneBytesIf utility</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-df1b62301c885e4cd4075140bdd989df1c9660b561033f8b56a56b605f5e7d18">+7/-6</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>util.go</strong><dd><code>Remove duplicate utilities and use
common package</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-005617216374ac58bf3cf72b81841d5cb6a17495d1d7b36ff387e294a0d6e043">+2/-87</a>&nbsp;
&nbsp; </td>

</tr>

<tr>
<td><strong>compile.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-1f95b23a5c61734c0686b47c14583f114fe66c015310f43992c517fa62c76f3d">+2/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>compile2.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-1c117d6b04a95023864b6b925099524a28e4ce3e4c8b6d93f4ab32d62cd4974e">+11/-3</a>&nbsp;
&nbsp; </td>

</tr>

<tr>
<td><strong>ddl.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-819bfdf891fa506cb2b4c89006896d528675fd554c341f38d1a1bf14a496c8aa">+2/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>scope.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-1a84d311b058e390f8c70e84f5e0c59dbd42736a85d022e2a283d926d43f5bd6">+3/-2</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>sql_executor.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-8d93841d90b6b267a1c218f24e1f564febdcc4dd780d04909033d706302ca215">+3/-6</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>func_mo.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-b553fa8d20dd9d505e58e3272ad74d359a50ce56152e523c8886ef1316b14ed9">+2/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>txn_table.go</strong><dd><code>Limit SQL logging to 500
characters</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-ec8d7fbb6765aa12484ff5529b88835dc1da369005256b065fb3db4972f2d32f">+1/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

</table></details></td></tr><tr><td><strong>Tests</strong></td><td><details><summary>4
files</summary><table>
<tr>
<td><strong>bytes_test.go</strong><dd><code>Tests for byte cloning
utilities</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-e0ee223e0dd8dbd06e10644be0d576d23f205e905a06cc3af94ce49585985a3b">+88/-0</a>&nbsp;
&nbsp; </td>

</tr>

<tr>
<td><strong>string_test.go</strong><dd><code>Tests for string
abbreviation function</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-266b890c079978ce53248b043bfdeef28ac0e94d97dc24715d420637326f295a">+53/-0</a>&nbsp;
&nbsp; </td>

</tr>

<tr>
<td><strong>util_test.go</strong><dd><code>Update test to use
commonutil.CloneBytes</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-682a3d8cc46973e1c1726fa8a8ece492f2a8aba302fb81cee8578934c29caea6">+2/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
<td><strong>util_test.go</strong><dd><code>Update tests for removed and
moved utilities</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-f51b6d5837418f5bbf801345e25b4bfcc4cd436bdec4534ab7a8aa8dc01839e0">+3/-15</a>&nbsp;
&nbsp; </td>

</tr>
</table></details></td></tr><tr><td><strong>Bug
fix</strong></td><td><details><summary>1 files</summary><table>
<tr>
<td><strong>server_query.go</strong><dd><code>Replace copyBytes with
commonutil.CloneBytes</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23229/files#diff-9155e9743825e69f57408c43feab229fd722006804cef7dffbf57a78d507d7c1">+5/-9</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>
</table></details></td></tr></tr></tbody></table>

</details>

___
@XuPeng-SH
XuPeng-SH deleted the optimize-logging-2 branch July 4, 2026 19:46
This pull request was closed.

This branch was previously deployed

1 inactive deployment
ci — a2b29d92 Deployed Dec 7, 2025 by ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor Code refactor Review effort 2/5 size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants