Project

General

Profile

« Previous | Next » 

Revision 2844

sql_gen.py: CompareCond.to_str(): Always wrap the left-side column if it's nullable. Wrap the right-side value if the left side was wrapped, rather than if both the left and right side are nullable. This causes coalesce() indexes to be used to look up NULL values using the value NULL gets coalesced to, rather than doing a sequential scan.

View differences:

lib/sql_gen.py
401 401
        operator = strings.remove_prefix('~', operator, passthru_null_ref)
402 402
        neg_ref = [False]
403 403
        operator = strings.remove_prefix('!', operator, neg_ref)
404
        equals = operator.endswith('=')
405
        if equals and is_null(right_value): operator = 'IS'
404
        equals = operator.endswith('=') # also includes <=, >=
406 405
        
407 406
        # Handle nullable columns
408 407
        check_null = False
409
        if equals and not passthru_null_ref[0] and isinstance(right_value, Col):
410
            check_null = True
411
            try:
412
                left_non_null = ensure_not_null(db, left_value)
413
                right_non_null = ensure_not_null(db, right_value)
414
            except ensure_not_null_excs: pass
408
        if not passthru_null_ref[0]: # NULLs compare equal
409
            try: left_non_null = ensure_not_null(db, left_value)
410
            except ensure_not_null_excs: # fall back to alternate method
411
                check_null = equals and isinstance(right_value, Col)
415 412
            else:
416
                if (left_non_null is not left_value
417
                    and right_non_null is not right_value): # both were wrapped
418
                    check_null = False # wrapping makes extra check unnecessary
413
                if left_non_null is not left_value: # wrapped, so wrap both
419 414
                    left_value = left_non_null
420
                    right_value = right_non_null
415
                    right_value = EnsureNotNull(right_value, left_value.args[1])
421 416
        
417
        if equals and is_null(right_value): operator = 'IS'
418
        
422 419
        left = left_value.to_str(db)
423 420
        right = right_value.to_str(db)
424 421
        

Also available in: Unified diff