Commit graph

50 commits

Author SHA1 Message Date
Igor Babaev
8d9dd21d85 Fixed LP bugs #717577, #724942.
Both these two bugs happened due to the following problem.
When a view column is referenced in the query an Item_direct_view_ref
object is created that is refers to the Item_field for the column.
All references to the same view column refer to the same Item_field.
Different references can belong to different AND/OR levels and,
as a result, can be included in different Item_equal object.
These Item_equal objects may include different constant objects.
If these constant objects are substituted for the Item_field created
for a view column we have a conflict situation when the second
substitution annuls the first substitution. This leads to
wrong result sets returned by the query. Bug #724942 demonstrates
such an erroneous behaviour.
Test case of the bug #717577 produces wrong result sets because best
equal fields of the multiple equalities built for different OR levels
of the WHERE condition differs. The subsitution for the best equal field
in the second OR branch overwrites the the substitution made for the
first branch.

To avoid such conflicts we have to substitute for the references
to the view columns rather than for the underlying field items.
To make such substitutions possible we have to include into
multiple equalities references to view columns rather than 
field items created for such columns.

This patch modifies the Item_equal class to include references
to view columns into multiple equality objects. It also performs
a clean up of the class methods and adds more comments. The methods
of the Item_direct_view_ref class that assist substitutions for
references to view columns has been also added by this patch.
2011-04-26 19:58:41 -07:00
Igor Babaev
84a0c9b2a2 Fixed LP bug #698882.
Made sure that the optimal fields are used by TABLE_REF objects
when building index access keys to joined tables.
Fixed a bug in the template function that sorts the elements of
a list using the bubble sort algorithm. The bug caused poor
performance of the function. Also added an optimization that
skips comparison with the most heavy elements that has been 
already properly placed in the list.
Made the comparison of the fields belonging to the same Item_equal
more granular: fields belonging to the same table are also ordered
according to some rules.
2011-01-15 11:14:36 -08:00
Michael Widenius
52090a4434 Code cleanup to get fewer reallocs() during execution.
- Changed TABLE->alias to String to get fewer reallocs when alias are used.
- Preallocate some buffers

Changed some String->c_ptr() -> String->ptr() when \0 is not needed.
Fixed wrong usage of String->ptr() when we need a \0 terminated string.
Use my_strtod() instead of my_atof() to avoid having to add \0 to string.
c_ptr() -> c_ptr_safe() to avoid warnings from valgrind.
zr 

sql/event_db_repository.cc:
  Update usage of TABLE->alias
sql/event_scheduler.cc:
  c_ptr() -> c_ptr_safe()
sql/events.cc:
  c_ptr() -> ptr() as \0 was not needed
sql/field.cc:
  Update usage of TABLE->alias
sql/field.h:
  Update usage of TABLE->alias
sql/ha_partition.cc:
  Update usage of TABLE->alias
sql/handler.cc:
  Update usage of TABLE->alias
  Fixed wrong usage of str.ptr()
sql/item.cc:
  Fixed error where code wrongly assumed string was \0 terminated.
sql/item_func.cc:
  c_ptr() -> c_ptr_safe()
  Update usage of TABLE->alias
sql/item_sum.h:
  Use my_strtod() instead of my_atof() to avoid having to add \0 to string
sql/lock.cc:
  Update usage of TABLE->alias
sql/log.cc:
  c_ptr() -> ptr() as \0 was not needed
sql/log_event.cc:
  c_ptr_quick() -> ptr() as \0 was not needed
sql/opt_range.cc:
  ptr() -> c_ptr() as \0 is needed
sql/opt_subselect.cc:
  Update usage of TABLE->alias
sql/opt_table_elimination.cc:
  Update usage of TABLE->alias
sql/set_var.cc:
  ptr() -> c_ptr() as \0 is needed
  c_ptr() -> c_ptr_safe()
sql/sp.cc:
  c_ptr() -> ptr() as \0 was not needed
sql/sp_rcontext.cc:
  
  Update usage of TABLE->alias
sql/sql_base.cc:
  Preallocate buffers
  Update usage of TABLE->alias
sql/sql_class.cc:
  Fix arguments to sprintf() to work even if string is not \0 terminated
sql/sql_insert.cc:
  Update usage of TABLE->alias
  c_ptr() -> ptr() as \0 was not needed
sql/sql_load.cc:
  Preallocate buffers
  Trivial optimizations
sql/sql_parse.cc:
  Trivial optimization
sql/sql_plugin.cc:
  c_ptr() -> ptr() as \0 was not needed
sql/sql_select.cc:
  Update usage of TABLE->alias
sql/sql_show.cc:
  Update usage of TABLE->alias
sql/sql_string.h:
  Added move() function to move allocated memory from one object to another.
sql/sql_table.cc:
  Update usage of TABLE->alias
  c_ptr() -> c_ptr_safe()
sql/sql_test.cc:
  ptr() -> c_ptr_safe()
sql/sql_trigger.cc:
  Update usage of TABLE->alias
  c_ptr() -> c_ptr_safe()
sql/sql_update.cc:
  Update usage of TABLE->alias
sql/sql_view.cc:
  ptr() -> c_ptr_safe()
sql/sql_yacc.yy:
  ptr() -> c_ptr()
sql/table.cc:
  
  Update usage of TABLE->alias
sql/table.h:
  Changed TABLE->alias to String to get fewer reallocs when alias are used.
storage/federatedx/ha_federatedx.cc:
  Use c_ptr_safe() to ensure strings are \0 terminated.
storage/maria/ha_maria.cc:
  Update usage of TABLE->alias
storage/myisam/ha_myisam.cc:
  Update usage of TABLE->alias
storage/xtradb/row/row0sel.c:
  Ensure that null bits in record are properly reset.
  (Old code didn't work as row_search_for_mysql() can be called twice while reading fields from one row.
2010-11-24 00:08:48 +02:00
Sergey Petrunya
72dd7575cd Merge 5.2->5.3
- Re-commit Monty's merge, partially fixed by Igor and SergeyP, 
  but still broken
2010-10-10 17:18:11 +03:00
Michael Widenius
d042146e5b Merge with MariaDB 5.1.49
Removed references to HA_END_SPACE_KEY (which has been 0 for a long time)
2010-08-05 22:56:11 +03:00
Sergey Petrunya
7df026676b Merge MariaDB-5.2 -> MariaDB 5.3 2010-03-20 15:01:47 +03:00
Sergey Petrunya
71a2047d6b Change Field_enumerator to enumerate Item_field-s not Field-s.
In Item_ref::fix_fields() do invoke mark_as_dependent() for outside 
references in all cases (see email for more details)

sql/item.cc:
  In Item_ref::fix_fields() do invoke mark_as_dependent() for outside references in all cases.
sql/item.h:
  Change Field_enumerator to enumerate Item_field-s not Field-s.
sql/item_subselect.cc:
  Change Field_enumerator to enumerate Item_field-s not Field-s.
sql/opt_table_elimination.cc:
  Change Field_enumerator to enumerate Item_field-s not Field-s.
2010-02-21 08:32:23 +02:00
Sergey Petrunya
69028d5127 LPBUG#523593: Running RQG optimizer_no_subquery crashes MariaDB
- When analying multiple equalities, take into account that they 
  may not have a single table field that belongs to one of the tables
  that we're trying to eliminate (and they are not useful for table
  elimination in that case)

mysql-test/r/table_elim.result:
  LPBUG#523593: Running RQG optimizer_no_subquery crashes MariaDB
  - Testcase
mysql-test/t/table_elim.test:
  LPBUG#523593: Running RQG optimizer_no_subquery crashes MariaDB
  - Testcase
2010-02-18 15:03:52 +03:00
Sergey Petrunya
b83cb52e9e Backport of subquery optimizations to 5.3.
There are still test failures because of:
- Wrong query results in outer join + semi join
- EXPLAIN output differences
2010-01-17 17:51:10 +03:00
Sergey Petrunya
2f93e7cd3f MWL#17: Table elimination: fixes for windows
include/my_global.h:
  MWL#17: Table elimination: fixes for windows
  - Add ALIGN_MAX_UNIT (assume malloc returns data aligned to this much)
mysql-test/r/table_elim.result:
  MWL#17: Table elimination: fixes for windows
  - Use only lower-case as EXPLAIN [EXTENDED] changes case of table names
    on windows
mysql-test/t/table_elim.test:
  MWL#17: Table elimination: fixes for windows
  - Use only lower-case as EXPLAIN [EXTENDED] changes case of table names
    on windows
sql/opt_table_elimination.cc:
  MWL#17: Table elimination: fixes for windows
  - Add extra alignment-padding-space for stack-allocated buffers.
2009-09-16 23:05:03 +04:00
unknown
be70bfe043 Fix compiler warnings. 2009-09-07 09:12:38 +02:00
Sergey Petrunya
24c2fea6ad MWL#17: Table elimination
- Address review feedback R4: better comments, formatting
2009-09-02 01:41:16 +04:00
Sergey Petrunya
d762bf21cc MWL#17: Table-elimination
- Addressing review feedback, generation 4.

include/my_global.h:
  Make ALIGN_PTR's action correspond to that of ALIGN_SIZE
sql/item.cc:
  MWL#17: Table-elimination
  - Review feedback: function renames, better comments
sql/item.h:
  MWL#17: Table-elimination
  - Review feedback: function renames, better comments
sql/item_cmpfunc.cc:
  MWL#17: Table-elimination
  - Review feedback: function renames, better comments
sql/item_subselect.cc:
  MWL#17: Table-elimination
  - Review feedback: function renames, better comments
sql/item_subselect.h:
  MWL#17: Table-elimination
  - Review feedback: function renames, better comments
sql/opt_table_elimination.cc:
  MWL#17: Table-elimination
  - Addressing review feedback, generation 4: abstract everything in case
    we would need to change it for something else in the future.
sql/sql_list.h:
  MWL#17: Table-elimination
  - Introduce exchange_sort(List<T> ...) template function
sql/sql_select.cc:
  MWL#17: Table-elimination
  - Review feedback: function renames, better comments
2009-09-01 00:02:09 +04:00
Sergey Petrunya
005c24e973 MWL#17: Table elimination:
- Fix a trivial problem when OR-merging two multi-equalities
- Amend testsuite to provide full gcov coverage

mysql-test/r/table_elim.result:
  MWL#17: Table elimination:
  - Amend testsuite to provide full gcov coverage
mysql-test/t/table_elim.test:
  MWL#17: Table elimination:
  - Amend testsuite to provide full gcov coverage
2009-08-27 01:01:40 +04:00
Sergey Petrunya
0e7a18e4a8 MWL#17: Table elimination
- Mark gcov deadcode
2009-08-25 17:59:15 +03:00
Sergey Petrunya
de41681afa MWL#17: Table elimination
- More test coverage
- Remove unused code
2009-08-25 13:38:22 +03:00
Sergey Petrunya
9400700b99 MWL#17: Table elimination
- Add more testcases.
- Fix trivial compile failure
- Remove handling of "column IN (one_element)". This is converted to equality 
  elsewhere

mysql-test/r/table_elim.result:
  MWL#17: Table elimination
  - Add more testcases.
  - Fix trivial compile failure
mysql-test/t/table_elim.test:
  MWL#17: Table elimination
  - Add more testcases
sql/mysqld.cc:
  MWL#17: Table elimination
  - Fix trivial compile failure
sql/opt_table_elimination.cc:
  MWL#17: Table elimination
  - Add more testcases.
  - Remove handling of "column IN (one_element)".This is converted to equality 
    elsewhere
2009-08-25 12:27:50 +03:00
Sergey Petrunya
d294aae6c8 MWL#17: Table elimination: last fixes
- Add an @@optimizer_switch flag for table_elimination for debug build
- Better comments 

mysql-test/t/index_merge_myisam.test:
  MWL#17: Table elimination: last fixes
  - Add an @@optimizer_switch flag for table_elimination for debug build
sql/mysql_priv.h:
  MWL#17: Table elimination: last fixes
  - Add an @@optimizer_switch flag for table_elimination for debug build
sql/mysqld.cc:
  MWL#17: Table elimination: last fixes
  - Add an @@optimizer_switch flag for table_elimination for debug build
2009-08-24 22:10:48 +03:00
Sergey Petrunya
21d2573908 MWL#17: Table elimination
- Correctly handle the case where we have multi-table DELETE and a table
  that we're deleting from looks like it could be eliminated.
2009-08-24 10:12:42 +02:00
Sergey Petrunya
f3d0b1c04e MWL#17: Table elimination
- Remove a piece of code that's not needed anymore.
2009-08-21 15:36:06 +02:00
Sergey Petrunya
9c1336801e MWL#17: Table elimination
- More testcases
- Set correct dependencies for non-bound multi-equalities.

mysql-test/r/table_elim.result:
  MWL#17: Table elimination
  - More testcases
mysql-test/t/table_elim.test:
  MWL#17: Table elimination
  - More testcases
sql/opt_table_elimination.cc:
  MWL#17: Table elimination
  - Set correct dependencies for non-bound multi-equalities.
2009-08-21 09:48:22 +02:00
Sergey Petrunya
3f5b494900 MWL#17: Table elimination
- Multiple-equality handling
2009-08-20 17:51:02 +02:00
Sergey Petrunya
46c9677628 Variable/function renames 2009-08-19 15:06:59 +03:00
Sergey Petrunya
c54370d3ff MWL#17: Table elimination
- Use Table_elimination only for functional dependency checking for
  individual objects and rename it to Func_dep_analyzer
2009-08-19 13:18:38 +03:00
Sergey Petrunya
eed5a47c34 More code cleanups 2009-08-19 01:19:48 +03:00
Sergey Petrunya
1396c2d2fa MWL#17: Table elimination
- Better comments
- Switch from "type" enum and switch to virtual functions for member funcs.
2009-08-19 00:18:10 +03:00
Sergey Petrunya
307a6ba5ee MWL#17: Table elimination
- Code cleanup
2009-08-18 18:01:51 +03:00
Sergey Petrunya
c1b69e72eb MWL#17: Table elimination
- Switch from trying to eliminate all tables at once (which didn't work)
  to the original approach of bottom-up elimination.
2009-08-18 16:03:58 +03:00
Sergey Petrunya
441434e565 MWL#17: Table elimination
- More dbug printouts
- More testcases
2009-08-17 18:02:29 +03:00
Sergey Petrunya
a14b5d2466 MWL#17: Table elimination
- More comments
2009-08-16 21:01:59 +03:00
Sergey Petrunya
69d4559eed MWL#17: Table elimination
- Better comments
- More OOM checks

sql/sql_select.cc:
  - Remove garbage code
2009-08-16 17:35:47 +03:00
Sergey Petrunya
e845f0f82f - Better comments
- Add OOM error checking
2009-08-16 15:43:31 +03:00
Sergey Petrunya
f260de5c07 MWL#17: Table elimination
- Address review feedback: change expression analyzer used to be a copy-paste
  of ref analyzer. ref analyzer, besides doing ref analysis, also collected 
  info about keys which had sargable predicates. We didn't need that part here.
2009-08-16 15:17:08 +03:00
Sergey Petrunya
b70cb552e5 MWL#17: Table elimination
- code cleanup
2009-08-16 12:15:49 +03:00
Sergey Petrunya
8c00930642 MWL#17: Table elimination
- Fix trivial valgrind failures that shown up after review
2009-08-16 10:25:24 +03:00
Sergey Petrunya
405a36ae39 MWL#17: Table elimination
- Review feedback, more variable renames
2009-08-15 18:39:12 +03:00
Sergey Petrunya
76071c8fbd Fix trivial typo 2009-08-15 16:14:42 +04:00
Sergey Petrunya
85b63c1e67 MWL#17: Table elimination
Continue with addressing review feedback part two: 
- rename enum members
- add checking for out of memory errors on allocation
2009-08-15 14:29:53 +04:00
Sergey Petrunya
ef67ab4d8b MWL#17: Address 2nd post-review feedback
- Switch from uniform graph to bipartite graph with two kinds of nodes:
  "values" (tables and fields) and "modules" (t.col=func(...) equalities, 
  multi-equalities, unique keys, inner sides of outer joins).
- Rename functions, classes, etc.
2009-08-15 10:08:03 +04:00
Sergey Petrunya
fef409cb9e MWL#17: Table elimination
- More function renames, added comments
2009-08-14 00:44:52 +04:00
Sergey Petrunya
a28390364b MWL#17: Table elimination
- Better comments

sql/sql_select.cc:
  MWL#17: Table elimination
  - Fix buildbot failure: do set correct value to nested_join::n_tables
2009-08-13 23:10:53 +04:00
Sergey Petrunya
536754c8c6 MWL#17: Table elimination
Fixes after post-review fixes:
- Don't search for tables in JOIN_TAB array. it's not initialized yet.
  use select_lex->leaf_tables instead.
2009-08-13 13:36:13 +04:00
Sergey Petrunya
40bb97b525 MWL#17: Table elimination
- When making inferences "field is bound" -> "key is bound", do check 
  that the field is part of the key
2009-08-13 04:01:43 +04:00
Sergey Petrunya
b032c7d833 MWL#17: Table elimination
- Continue addressing review feedback: remove "unusable KEYUSEs" 
  extension as it is no longer needed.

sql/item.h:
  MWL#17: Table elimination
  - Code cleanup
sql/opt_table_elimination.cc:
  MWL#17: Table elimination
  - Code cleanup
2009-08-13 03:43:02 +04:00
Sergey Petrunya
854bb82bd8 MWL#17: Table elimination
Address review feedback: 
- Change from Wave-based approach (a-la const table detection) to 
  building and walking functional dependency graph.
- Change from piggy-backing on ref-access code and KEYUSE structures
  to using our own expression analyzer.


sql/item.cc:
  MWL#17: Table elimination
  - Move from C-ish Field_processor_info to C++ ish and generic Field_enumerator
sql/item.h:
  MWL#17: Table elimination
  - Move from C-ish Field_processor_info to C++ ish and generic Field_enumerator
sql/sql_bitmap.h:
  MWL#17: Table elimination
  - Backport of Table_map_iterator from 6.0
2009-08-13 02:34:21 +04:00
Sergey Petrunya
7b3d464578 MWL#17: Table elimination
- More comments
- Renove old code
2009-06-30 17:20:18 +04:00
Sergey Petrunya
8156d9eb0a MWL#17: Table elimination
- Last fixes

sql/item.cc:
  MWL#17: Table elimination
  - Don't make multiple calls of ::walk(check_column_usage_processor),
    call once and cache the value
sql/item.h:
  MWL#17: Table elimination
  - s/KEYUSE::usable/KEYUSE::type/, more comments
sql/opt_table_elimination.cc:
  MWL#17: Table elimination
  - Don't make multiple calls of ::walk(check_column_usage_processor),
    call once and cache the value
sql/sql_select.cc:
  MWL#17: Table elimination
  - s/KEYUSE::usable/KEYUSE::type/, more comments
sql/sql_select.h:
  MWL#17: Table elimination
  - s/KEYUSE::usable/KEYUSE::type/, more comments
sql/table.h:
  MWL#17: Table elimination
  - Better comments
2009-06-30 17:11:00 +04:00
Sergey Petrunya
9fa1bce436 MWL#17: Table elimination
mysql-test/r/table_elim.result:
  MWL#17: Table elimination
  - More tests
mysql-test/t/table_elim.test:
  MWL#17: Table elimination
  - More tests
sql/opt_table_elimination.cc:
  MWL#17: Table elimination
  - Code cleanup
sql/sql_select.cc:
  MWL#17: Table elimination
  - Code cleanup
sql/sql_select.h:
  MWL#17: Table elimination
  - Code cleanup
sql/table.h:
  MWL#17: Table elimination
  - Code cleanup
2009-06-29 17:51:15 +04:00
Sergey Petrunia
d764108a2c MWL#17: Table elimination
- Better comments, variable/function renames
2009-06-26 00:07:29 +04:00
Sergey Petrunia
4102605fba MWL#17: Table elimination
- Moved table elimination code to sql/opt_table_elimination.cc
- Added comments 

.bzrignore:
  MWL#17: Table elimination
  - Moved table elimination code to sql/opt_table_elimination.cc
libmysqld/Makefile.am:
  MWL#17: Table elimination
  - Moved table elimination code to sql/opt_table_elimination.cc
sql/CMakeLists.txt:
  MWL#17: Table elimination
  - Moved table elimination code to sql/opt_table_elimination.cc
sql/Makefile.am:
  MWL#17: Table elimination
  - Moved table elimination code to sql/opt_table_elimination.cc
2009-06-25 14:05:53 +04:00