Skip to content

Conversation

@OreoYang
Copy link
Owner

Summary

This PR improves code quality in src/backend/utils/misc/ivy_guc.c by fixing multiple issues identified during code review.

Changes

Performance Improvements

  • Optimize nls_case_conversion() function: Cache strlen() result in a local variable to avoid O(N²) complexity, improving performance to O(N)
    • Previously: strlen() called on every loop iteration
    • Now: Called once at the start of each conversion cycle

Code Quality Fixes

  • Replace magic numbers with character constants: Improve readability by using 'a', 'z', 'A', 'Z' instead of ASCII codes (97, 122, 65, 90)

Bug Fixes

  • Fix typo in comment (line 59): "blow" → "below"
  • Fix typo in gettext string (line 423): "charater" → "character"
  • Fix typo in error message (line 480): Remove double period
  • Remove trailing whitespace in comment (line 187)

PostgreSQL Standards Compliance

  • Add missing errcode() to ereport() calls (lines 582, 584-585, 604-605):
    • Use ERRCODE_STRING_DATA_RIGHT_TRUNCATION for parameter length validation
    • Use ERRCODE_INVALID_PARAMETER_VALUE for NLS errors
    • Ensures proper error handling following PostgreSQL error reporting standards

Test Plan

✅ All regression tests passed:

  • PostgreSQL Tests: 228 tests passed
  • Oracle Tests: 235 tests passed (including Oracle-specific tests)
  • Oracle Extension Tests: contrib/ivorysql_ora tests passed

Files Changed

  • src/backend/utils/misc/ivy_guc.c (+25, -17)

Impact

  • No functional changes to GUC parameter behavior
  • Improves code maintainability and readability
  • Optimizes performance of character case conversion
  • Ensures PostgreSQL error reporting standards compliance

@OreoYang OreoYang force-pushed the test/review_from_codebuddy branch 2 times, most recently from ee19595 to 56b151f Compare January 22, 2026 08:15
- Fix typo in comment (line 59): "blow" → "below"
- Remove trailing whitespace in comment (line 187)
- Fix typo in gettext (line 423): "charater" → "character"
- Fix typo in error message (line 480): remove double period
- Add errcode() to ereport() calls (lines 582, 584-585, 604-605):
  * ERRCODE_STRING_DATA_RIGHT_TRUNCATION for length check
  * ERRCODE_INVALID_PARAMETER_VALUE for NLS errors
- Optimize nls_case_conversion() by caching strlen() result
  Change O(N²) to O(N) performance complexity
- Replace magic numbers with character constants:
  * 97, 122 → 'a', 'z'
  * 65, 90 → 'A', 'Z'

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@OreoYang OreoYang force-pushed the test/review_from_codebuddy branch from 56b151f to e1315e7 Compare January 22, 2026 08:39
@OreoYang OreoYang closed this Jan 22, 2026
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