Knowledge (XXG)

Sargable

Source 📝

125: 63: 22: 295:
non-sargable is to include in the WHERE clause a function operating on a column value. The WHERE clause is not the only clause where sargability can matter; it can also have an effect on ORDER BY, GROUP BY and HAVING clauses. The SELECT clause, on the other hand, can contain non-sargable
303:. Conceptually, an index is simply a mapping between a value and one or more locations. With a functional index, the value stored in the index is the output of the function specified when the index is created. This capability expands what is sargable beyond base column expressions. 505:
This is sargable because myIntField is NOT contained in a function, making any available indexes on myIntField potentially usable. Furthermore, the expression is evaluated only once, rather than for each record in the table.
287:
is to convert them to be sargable. The effect is similar to searching for a specific term in a book that has no index, beginning at page one each time, instead of jumping to a list of specific pages identified in an index.
279:
matching query to indexes instead of a complex, time-consuming cost-based search, thus it is often desired to write sargable queries. A query failing to be sargable is known as a
135: 409:
clauses that are sargable typically have field values on the left of the operator, and scalar values or expressions on the right side of the operator.
723: 687: 836: 793: 768: 852: 815: 219: 106: 49: 73: 456:
because myIntField is embedded in a function. If any indexes were available on myIntField, they could not be used. In addition,
150: 717:"CMU 15-721 :: Advanced Database Systems (Spring 2023) :: Lecture #16 Optimizer Implementation (Part 1) - Slide" 692: 193: 165: 88: 84: 857: 35: 172: 256:
researchers as a contraction of Search ARGument, and has come to mean simply "can be looked up by an index."
179: 831:
by Kalen Delaney, Connor Cunningham, Jonathan Kehayias, Benjamin Nevarez, Paul S. Randal (O'Reily, 2013)
621:
This is sargable. It can use an index to find all the myNameField values that start with the substring
716: 233: 161: 300: 688:
SQL Shack - How to use sargable expressions in T-SQL queries; performance advantages and examples
641: 284: 747:
Selinger, P. Griffiths; Astrahan, M. M.; Chamberlin, D. D.; Lorie, R. A.; Price, T. G. (1979).
832: 811: 789: 764: 753:
Proceedings of the 1979 ACM SIGMOD international conference on Management of data - SIGMOD '79
636: 756: 245: 260: 819: 748: 661: 186: 846: 41: 248:
to speed up the execution of the query. The term is derived from a contraction of
578:
sargable. It must examine every row to find the fields containing the substring
283:
query and typically has a negative effect on query time, so one of the steps in
124: 272: 525:
clauses that are sargable have field values on the left of the operator, and
292: 276: 760: 91:. Statements consisting only of original research should be removed. 788:(7th ed.). New York, NY: McGraw-Hill Education. p. 773. 749:"Access path selection in a relational database management system" 693:
DBA.StackExchange.com - What does the word “SARGable” really mean?
268: 241: 784:
Silberschatz, Abraham; Korth, Henry F.; Sudarshan, S. (2020).
253: 118: 56: 15: 142: 296:
expressions without adversely affecting the performance.
810:
by Peter Gulutzan, Trudy Pelzer (Addison Wesley, 2002)
146: 80: 236:, a condition (or predicate) in a query is said to be 366:
Sargable operators that rarely improve performance:
622: 579: 532: 526: 520: 514: 457: 404: 367: 308: 299:Some database management systems, for instance 8: 465:would be called on every record in myTable. 151:introducing citations to additional sources 50:Learn how and when to remove these messages 677:gives an example of such simple heuristic. 220:Learn how and when to remove this message 107:Learn how and when to remove this message 531:text strings that do not begin with the 141:Relevant discussion may be found on the 704: 616:-- Does not begin with %, sargable 291:The typical situation that will make a 301:PostgreSQL, support functional indices 271:workloads because it suggests a good 7: 710: 708: 829:Microsoft SQL Server 2012 Internals 569:-- Begins with %, not sargable 672: 14: 839:(Chapter 11, The Query Optimizer) 655: 31:This article has multiple issues. 244:engine can take advantage of an 134:relies largely or entirely on a 123: 61: 20: 729:from the original on 2023-06-01 39:or discuss these issues on the 1: 275:can be obtained by a simple 267:is an important property in 853:Database management systems 715:Andy, Pavlo (Spring 2023). 87:the claims made and adding 876: 755:. ACM Press. p. 23. 786:Database system concepts 589: 542: 470: 414: 252:. It was first used by 808:SQL Performance Tuning 660:Gulutzan and Pelzer, ( 761:10.1145/582095.582099 307:Sargable operators: 250:Search ARGument ABLE 234:relational databases 147:improve this article 642:Query optimization 587:Sargable version: 468:Sargable version: 285:query optimization 72:possibly contains 837:978-0-7356-5856-1 822:Simple "Searches" 795:978-1-260-08450-4 770:978-0-89791-001-9 664:Simple "Searches" 637:Block Range Index 584:in any position. 566:'%Wales%' 230: 229: 222: 212: 211: 197: 117: 116: 109: 74:original research 54: 865: 858:Relational model 800: 799: 781: 775: 774: 744: 738: 737: 735: 734: 728: 721: 712: 676: 659: 626: 625: 617: 614: 613:'Jimmy%' 611: 608: 605: 602: 599: 596: 593: 583: 582: 570: 567: 564: 561: 558: 555: 552: 549: 546: 536: 535: 530: 529: 524: 523: 518: 517: 501: 498: 495: 492: 489: 486: 483: 480: 477: 474: 464: 463: 460: 448: 445: 442: 439: 436: 433: 430: 427: 424: 421: 418: 408: 407: 395: 394: 391: 388: 385: 382: 379: 376: 373: 370: 363: 362: 359: 356: 353: 350: 347: 344: 341: 338: 335: 332: 329: 326: 323: 320: 317: 314: 311: 261:query optimizers 225: 218: 207: 204: 198: 196: 155: 127: 119: 112: 105: 101: 98: 92: 89:inline citations 65: 64: 57: 46: 24: 23: 16: 875: 874: 868: 867: 866: 864: 863: 862: 843: 842: 804: 803: 796: 783: 782: 778: 771: 746: 745: 741: 732: 730: 726: 719: 714: 713: 706: 701: 684: 670: 653: 650: 633: 624:'Jimmy' 623: 619: 618: 615: 612: 609: 606: 603: 600: 597: 594: 591: 581:'Wales' 580: 572: 571: 568: 565: 562: 559: 556: 553: 550: 547: 544: 533: 527: 521: 515: 512: 503: 502: 499: 496: 493: 490: 487: 484: 481: 478: 475: 472: 461: 458: 450: 449: 446: 443: 440: 437: 434: 431: 428: 425: 422: 419: 416: 405: 402: 392: 389: 386: 383: 380: 377: 374: 371: 368: 360: 357: 354: 351: 348: 345: 342: 339: 336: 333: 330: 327: 324: 321: 318: 315: 312: 309: 226: 215: 214: 213: 208: 202: 199: 156: 154: 140: 128: 113: 102: 96: 93: 78: 66: 62: 25: 21: 12: 11: 5: 873: 872: 869: 861: 860: 855: 845: 844: 841: 840: 826: 802: 801: 794: 776: 769: 739: 703: 702: 700: 697: 696: 695: 690: 683: 682:External links 680: 679: 678: 668: 649: 646: 645: 644: 639: 632: 629: 590: 543: 540:Not sargable: 537:on the right. 511: 508: 471: 415: 412:Not sargable: 401: 400:Simple example 398: 397: 396: 364: 228: 227: 210: 209: 145:. Please help 131: 129: 122: 115: 114: 69: 67: 60: 55: 29: 28: 26: 19: 13: 10: 9: 6: 4: 3: 2: 871: 870: 859: 856: 854: 851: 850: 848: 838: 834: 830: 827: 824: 823: 817: 816:0-201-79169-2 813: 809: 806: 805: 797: 791: 787: 780: 777: 772: 766: 762: 758: 754: 750: 743: 740: 725: 718: 711: 709: 705: 698: 694: 691: 689: 686: 685: 681: 675: 674: 669: 666: 665: 658: 657: 652: 651: 647: 643: 640: 638: 635: 634: 630: 628: 588: 585: 577: 541: 538: 509: 507: 469: 466: 455: 413: 410: 399: 365: 306: 305: 304: 302: 297: 294: 289: 286: 282: 278: 274: 270: 266: 262: 259:For database 257: 255: 251: 247: 243: 239: 235: 224: 221: 206: 195: 192: 188: 185: 181: 178: 174: 171: 167: 164: –  163: 159: 158:Find sources: 152: 148: 144: 138: 137: 136:single source 132:This article 130: 126: 121: 120: 111: 108: 100: 90: 86: 82: 76: 75: 70:This article 68: 59: 58: 53: 51: 44: 43: 38: 37: 32: 27: 18: 17: 828: 821: 807: 785: 779: 752: 742: 731:. Retrieved 671: 663: 654: 620: 586: 575: 573: 539: 513: 510:Text example 504: 467: 454:not sargable 453: 451: 411: 403: 298: 290: 281:non-sargable 280: 264: 258: 249: 237: 231: 216: 200: 190: 183: 176: 169: 157: 133: 103: 94: 71: 47: 40: 34: 33:Please help 30: 820:Chapter 2, 662:Chapter 2, 607:myNameField 560:myNameField 97:August 2015 847:Categories 733:2024-01-25 699:References 488:myIntField 438:myIntField 273:query plan 203:April 2013 173:newspapers 162:"Sargable" 81:improve it 36:improve it 293:SQL query 277:heuristic 143:talk page 85:verifying 42:talk page 724:Archived 631:See also 574:This is 452:This is 369:<> 265:sargable 238:sargable 601:myTable 554:myTable 482:myTable 426:myTable 340:BETWEEN 240:if the 187:scholar 79:Please 835:  814:  792:  767:  592:SELECT 545:SELECT 473:SELECT 417:SELECT 189:  182:  175:  168:  160:  727:(PDF) 720:(PDF) 648:Notes 604:WHERE 557:WHERE 516:WHERE 485:WHERE 429:WHERE 406:WHERE 334:<= 328:>= 246:index 194:JSTOR 180:books 833:ISBN 812:ISBN 790:ISBN 765:ISBN 610:LIKE 598:FROM 563:LIKE 551:FROM 528:LIKE 522:LIKE 519:... 500:11.7 494:11.7 491:> 479:FROM 459:SQRT 447:11.7 444:> 432:SQRT 423:FROM 393:LIKE 355:NULL 346:LIKE 322:< 316:> 269:OLTP 242:DBMS 166:news 757:doi 576:not 390:NOT 381:NOT 375:NOT 254:IBM 232:In 149:by 83:by 849:: 763:. 751:. 722:. 707:^ 673:^2 656:^1 627:. 462:() 384:IN 361:IN 352:IS 263:, 45:. 825:) 818:( 798:. 773:. 759:: 736:. 667:) 595:* 548:* 534:% 497:* 476:* 441:) 435:( 420:* 387:, 378:, 372:, 358:, 349:, 343:, 337:, 331:, 325:, 319:, 313:, 310:= 223:) 217:( 205:) 201:( 191:· 184:· 177:· 170:· 153:. 139:. 110:) 104:( 99:) 95:( 77:. 52:) 48:(

Index

improve it
talk page
Learn how and when to remove these messages
original research
improve it
verifying
inline citations
Learn how and when to remove this message

single source
talk page
improve this article
introducing citations to additional sources
"Sargable"
news
newspapers
books
scholar
JSTOR
Learn how and when to remove this message
relational databases
DBMS
index
IBM
query optimizers
OLTP
query plan
heuristic
query optimization
SQL query

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.