sql_optimizer.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. sql_optimizer_tests = [
  2. (
  3. "select * from person where (age < 18) or (age > 60 and age < 35);",
  4. {
  5. "select_cols": [
  6. {
  7. "target": {
  8. "type": "select_all_column",
  9. "value": "select_all_column",
  10. },
  11. "type": "select_all_column",
  12. }
  13. ],
  14. "table_names": ["person"],
  15. "type": "select_stmt",
  16. "where": {
  17. "left": {"type": "identifier", "value": "age"},
  18. "op_type": "bin_cmp_op",
  19. "right": {"type": "int", "value": 18},
  20. "type": "小于",
  21. },
  22. },
  23. ),
  24. (
  25. "select * from person where (age < 18) and age < 5 and age < 35;",
  26. {
  27. "select_cols": [
  28. {
  29. "target": {
  30. "type": "select_all_column",
  31. "value": "select_all_column",
  32. },
  33. "type": "select_all_column",
  34. }
  35. ],
  36. "table_names": ["person"],
  37. "type": "select_stmt",
  38. "where": {
  39. "left": {"type": "identifier", "value": "age"},
  40. "op_type": "bin_cmp_op",
  41. "right": {"type": "int", "value": 5},
  42. "type": "小于",
  43. },
  44. },
  45. ),
  46. (
  47. "select * from person where age < 18 and (age > 5 and age > 35);",
  48. {
  49. "select_cols": [
  50. {
  51. "target": {
  52. "type": "select_all_column",
  53. "value": "select_all_column",
  54. },
  55. "type": "select_all_column",
  56. }
  57. ],
  58. "table_names": ["person"],
  59. "type": "select_stmt",
  60. "where": {"type": "bool", "value": False},
  61. },
  62. ),
  63. (
  64. """select person.name
  65. from person join class
  66. on age=22 and class.id=person.classId ;
  67. """,
  68. {
  69. "join_options": {
  70. "join_with": {"type": "identifier", "value": "class"},
  71. "on": {
  72. "left": {"field": "id", "table": "class", "type": "table_field"},
  73. "op_type": "bin_cmp_op",
  74. "right": {
  75. "field": "classId",
  76. "table": "person",
  77. "type": "table_field",
  78. },
  79. "type": "相等",
  80. },
  81. "type": "join_options",
  82. },
  83. "select_cols": [
  84. {
  85. "target": {
  86. "field": "name",
  87. "table": "person",
  88. "type": "table_field",
  89. },
  90. "type": "select_column",
  91. }
  92. ],
  93. "table_names": ["person"],
  94. "type": "select_stmt",
  95. "where": {
  96. "left": {"type": "identifier", "value": "age"},
  97. "op_type": "bin_cmp_op",
  98. "right": {"type": "int", "value": 22},
  99. "type": "相等",
  100. },
  101. },
  102. ),
  103. (
  104. """select person.name
  105. from person join class
  106. on age=22;
  107. """,
  108. {
  109. "join_options": {
  110. "join_with": {"type": "identifier", "value": "class"},
  111. "on": {},
  112. "type": "join_options",
  113. },
  114. "select_cols": [
  115. {
  116. "target": {
  117. "field": "name",
  118. "table": "person",
  119. "type": "table_field",
  120. },
  121. "type": "select_column",
  122. }
  123. ],
  124. "table_names": ["person"],
  125. "type": "select_stmt",
  126. "where": {
  127. "left": {"type": "identifier", "value": "age"},
  128. "op_type": "bin_cmp_op",
  129. "right": {"type": "int", "value": 22},
  130. "type": "相等",
  131. },
  132. },
  133. ),
  134. ]