Skip to content

Conversation

@zywoote3ture
Copy link
Contributor

What problem were solved in this pull request?

Issue Number: close #620
屏幕截图 2025-12-06 153556
屏幕截图 2025-12-06 153623

Problem:

What is changed and how it works?

Other information

Signed-off-by: zywoote3ture <3355324252@qq.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes issue #620 by disabling index scan for the NOT_EQUAL (<>) operator in query optimization. The change ensures that queries using NOT_EQUAL operations fall back to table scan instead of using index scan, which was producing incorrect results.

Key Changes:

  • Modified the comparison operator filter to exclude NOT_EQUAL from index optimization consideration
  • Added tracking of the target comparison operator to detect NOT_EQUAL operations
  • Added conditional check to prevent index usage when NOT_EQUAL is detected
  • Added diagnostic logging for NOT_EQUAL operations that use table scan

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

auto comparison_expr = static_cast<ComparisonExpr *>(expr.get());
// 简单处理,就找等值查询
if (comparison_expr->comp() != EQUAL_TO && comparison_expr->comp() != NOT_EQUAL) {
if (comparison_expr->comp() != EQUAL_TO ) {
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here is problematic. The code now only allows EQUAL_TO comparisons to proceed, but then later checks if target_op == NOT_EQUAL (line 165). This creates a logical inconsistency: if NOT_EQUAL comparisons are filtered out here with continue, then target_op can never be set to NOT_EQUAL at line 165.

The original code allowed both EQUAL_TO and NOT_EQUAL to proceed, which made sense if the intent is to detect NOT_EQUAL operations and disable index usage for them. This change breaks that detection logic.

Suggested change
if (comparison_expr->comp() != EQUAL_TO ) {
if (comparison_expr->comp() != EQUAL_TO && comparison_expr->comp() != NOT_EQUAL) {

Copilot uses AI. Check for mistakes.
Comment on lines 196 to +204
LOG_TRACE("use table scan");
if(target_op == NOT_EQUAL)
{
LOG_TRACE("not equal operation,use table scan instead of index scan");
}
else
{
LOG_TRACE("use table scan");
}
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated and redundant logging logic. This code logs "use table scan" unconditionally at line 196, then has a conditional block (lines 197-204) that logs either a specific message for NOT_EQUAL or "use table scan" again. This results in duplicate "use table scan" messages being logged for most cases.

Recommend removing the LOG_TRACE at line 196 and keeping only the conditional logging block, or simplifying to just use the conditional logging.

Copilot uses AI. Check for mistakes.
return RC::SUCCESS;
}


Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Unnecessary blank line added. This extra blank line is inconsistent with the rest of the file's formatting and should be removed.

Suggested change

Copilot uses AI. Check for mistakes.
LOG_TRACE("use table scan");
if(target_op == NOT_EQUAL)
{
LOG_TRACE("not equal operation,use table scan instead of index scan");
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after comma in log message. Should be "not equal operation, use table scan instead of index scan" for proper formatting.

Suggested change
LOG_TRACE("not equal operation,use table scan instead of index scan");
LOG_TRACE("not equal operation, use table scan instead of index scan");

Copilot uses AI. Check for mistakes.
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.

Title: Index Scan Returns Incorrect Results for Not Equal Operator (<>)

1 participant