mariadb/mysql-test/r
Neeraj Bisht 35a3f9d76c Bug#12328597 - MULTIPLE COUNT(DISTINCT) IN SAME SELECT FALSE
WITH COMPOSITE KEY COLUMNS

Problem:-
While running a SELECT query with several AGGR(DISTINCT) function 
and these are referring to different field of same composite key, 
Returned incorrect value.

Analysis:-

In a table, where we have composite key like (a,b,c)
and when we give a query like

select COUNT(DISTINCT b), SUM(DISTINCT a) from ....

here, we first make a list of items in Aggr(distinct) function
(which is a, b), where order of item doesn't matter. 
and then we see, whether we have a composite key where the prefix 
of index columns matches the items of the aggregation function.
(in this case we have a,b,c).

if yes, so we can use loose index scan and we need not perform 
duplicate removal to distinct in our aggregate function.

In our table, we traverse column marked with <-- and get the result as
(a,b,c)      count(distinct b)           sum(distinct a)
             treated as count b          treated as sum(a)
(1,1,2)<--              1                      1		
(1,2,2)<--              1++=2                  1+1=2
(1,2,3)		
(2,1,2)<--              2++=3                  1+1+2=4
(2,2,2)<--              3++=4                  1+1+2+2=6
(2,2,3)

result will be 4,6, but it should be (2,3)

As in this case, our assumption is incorrect. If we have
query like 
select count(distinct a,b), sum(distinct a,b)from ..
then we can use loose index scan

Solution:-
In our query, when we have more then one aggr(distinct) function 
then they should refer to same  fields like

select count(distinct a,b), sum(distinct a,b) from .. 

-->we can use loose scan index as both aggr(distinct) refer to same fields a,b.

If they are referring to different field like

select count(distinct a), sum(distinct b) from .. 

-->will not use loose scan index as both aggr(distinct) refer to different fields.
2013-05-13 17:15:25 +05:30
..
1st.result
alias.result
almost_full.result
alter_table-big.result
alter_table.result
analyze.result
ansi.result
archive-big.result
archive.result
archive_bitfield.result
archive_debug.result
archive_gis.result
archive_plugin.result
auth_rpl.result
auto_increment.result
backup.result
bench_count_distinct.result
big_test.require
bigint.result
binary.result
binlog_tx_isolation.result
blackhole.result
blackhole_plugin.result
bool.result
bootstrap.result
bug39022.result
bug46080.result
bug46261.result
bug46760.result
bug47671.result
bug58669.result
bug12427262.result
bug13633383.result
bulk_replace.result
cache_innodb.result
case.result
case_insensitive_file_system.require
case_insensitive_fs.require
case_sensitive_file_system.require
cast.result Bug#14096619: UNABLE TO RESTORE DATABASE DUMP 2013-01-31 07:06:30 +05:30
change_user.result
check.result
check_var_limit.require
client_xml.result
comment_column.result
comment_column2.result
comment_index.result
comment_table.result
comments.result
commit.result
commit_1innodb.result
compare.result
compress.result
concurrent_innodb_safelog.result
concurrent_innodb_unsafelog.result
connect.result
consistent_snapshot.result
constraints.result
contributors.result WL#6454: Deprecate SHOW AUTHORS and SHOW CONTRIBUTORS 2012-09-11 16:29:51 +02:00
count_distinct.result
count_distinct2.result
count_distinct3.result
crash_commit_before.result
create-big.result
create.result
create_not_windows.result
create_select_tmp.result
csv.result
csv_alter_table.result
csv_not_null.result
ctype_ascii.result
ctype_big5.result
ctype_binary.result manual merge (WL6219) 2012-06-29 14:12:21 +04:00
ctype_collate.result
ctype_cp932_binlog_row.result
ctype_cp932_binlog_stm.result
ctype_cp1250_ch.result
ctype_cp1251.result manual merge (WL6219) 2012-06-29 14:12:21 +04:00
ctype_create.result
ctype_errors.result
ctype_eucjpms.result
ctype_euckr.result
ctype_filename.result
ctype_filesystem.result
ctype_gb2312.result
ctype_gbk.result
ctype_gbk_binlog.result
ctype_hebrew.result
ctype_latin1.result manual merge (WL6219) 2012-06-29 14:12:21 +04:00
ctype_latin1_de.result
ctype_latin2.result
ctype_latin2_ch.result
ctype_ldml.result
ctype_like_range.result
ctype_many.result
ctype_mb.result
ctype_recoding.result
ctype_sjis.result
ctype_tis620.result
ctype_uca.result
ctype_ucs.result Description: 2012-09-26 17:04:19 +05:30
ctype_ucs2_def.result
ctype_ujis.result
ctype_ujis_ucs2.result
ctype_utf8.result manual merge (WL6219) 2012-06-29 14:12:21 +04:00
ctype_utf8mb4.result Bug#14096619: UNABLE TO RESTORE DATABASE DUMP 2013-01-31 07:06:30 +05:30
ctype_utf8mb4_heap.result
ctype_utf8mb4_innodb.result
ctype_utf8mb4_myisam.result
ctype_utf16.result
ctype_utf16_def.result
ctype_utf16_uca.result
ctype_utf32.result
ctype_utf32_uca.result
date_formats.result
ddl_i18n_koi8r.result Bug#14463669 FAILURE TO CORRECTLY PARSE ROUTINES IN 2012-11-20 11:30:39 +05:30
ddl_i18n_utf8.result Bug#14463669 FAILURE TO CORRECTLY PARSE ROUTINES IN 2012-11-20 11:53:54 +05:30
deadlock_innodb.result
debug_sync.result
default.result
delayed.result
delete.result
deprecated_features.result
derived.result
dirty_close.result
disabled_partition.require
distinct.result
drop-no_root.result
drop.result
drop_debug.result
empty_table.result
endspace.result
error_simulation.result
errors.result
events_1.result
events_2.result
events_bugs.result
events_embedded.result
events_grant.result
events_logs_tests.result
events_microsec.result
events_restart.result
events_scheduling.result
events_stress.result
events_time_zone.result
events_trans.result
events_trans_notembedded.result
execution_constants.result
explain.result
file_contents.result
filesort_debug.result
fix_priv_tables.result
flush.result
flush2.result
flush_block_commit.result
flush_block_commit_notembedded.result
flush_read_lock.result
flush_read_lock_kill.result
flush_table.result
foreign_key.result
fulltext.result
fulltext2.result
fulltext3.result
fulltext_cache.result
fulltext_distinct.result
fulltext_left_join.result
fulltext_multi.result
fulltext_order_by.result
fulltext_plugin.result
fulltext_update.result
fulltext_var.result
func_analyse.result
func_compress.result Bug#16084594 USER_VAR ITEM IN 'LOAD FILE QUERY' WAS NOT 2013-01-28 14:58:55 +05:30
func_concat.result
func_crypt.result
func_date_add.result
func_default.result
func_des_encrypt.result
func_digest.result
func_encrypt.result
func_encrypt_nossl.result
func_encrypt_ucs2.result
func_equal.result
func_gconcat.result
func_group.result manual merge (WL6219) 2012-06-29 14:12:21 +04:00
func_group_innodb.result
func_if.result
func_in.result
func_isnull.result
func_like.result
func_math.result Bug#16084594 USER_VAR ITEM IN 'LOAD FILE QUERY' WAS NOT 2013-01-28 14:58:55 +05:30
func_misc.result
func_op.result
func_regexp.result
func_rollback.result
func_sapdb.result
func_set.result
func_str.result
func_system.result
func_test.result
func_time.result
func_timestamp.result
gcc296.result
gis-rtree.result
gis.result
grant.result
grant2.result
grant3.result
grant4.result
grant_cache_no_prot.result
grant_cache_ps_prot.result
grant_lowercase_fs.result
greedy_optimizer.result
group_by.result
group_min_max.result Bug#12328597 - MULTIPLE COUNT(DISTINCT) IN SAME SELECT FALSE 2013-05-13 17:15:25 +05:30
group_min_max_innodb.result Merging from mysql-5.1 to mysql-5.5. 2012-12-11 10:51:24 +05:30
handler_innodb.result
handler_myisam.result
handler_read_last.result
have_big5.require
have_binlog_format_mixed.require
have_binlog_format_row.require
have_binlog_format_statement.require
have_compress.require
have_cp866.require
have_cp932.require
have_cp1250_ch.require
have_cp1251.require
have_crypt.require
have_debug.require
have_debug_sync.require
have_eucjpms.require
have_euckr.require
have_gb2312.require
have_gbk.require
have_geometry.require
have_koi8r.require
have_latin2_ch.require
have_local_infile.require
have_log_bin.require
have_met_timezone.require
have_moscow_leap_timezone.require
have_mysql_upgrade.result
have_ndb_extra.require
have_ndbapi_examples.require
have_nodebug.require
have_outfile.require
have_partition.require
have_perror.require
have_profiling.require
have_query_cache.require
have_sjis.require
have_ssl.require
have_ssl_is_yes_or_disabled_only.require
have_symlink.require
have_tis620.require
have_ucs2.require
have_ujis.require
have_utf8.require
have_utf8mb4.require
have_utf16.require
have_utf32.require
having.result
heap.result
heap_auto_increment.result
heap_btree.result
heap_hash.result
help.result
implicit_char_to_num_conversion.result
implicit_commit.result
index_merge_innodb.result
index_merge_myisam.result
information_schema-big.result
information_schema.result Bug #13113026 INFORMATION_SCHEMA.INNODB_BUFFER_PAGE_LRUFROM 5.6 BACKPORT 2012-07-25 10:48:16 +05:30
information_schema_chmod.result
information_schema_db.result
information_schema_inno.result
information_schema_parameters.result
information_schema_part.result
information_schema_routines.result
init_connect.result
init_file.result
innodb_ignore_builtin.result
innodb_mysql_lock.result
innodb_mysql_lock2.result
innodb_mysql_sync.result
insert.result
insert_notembedded.result
insert_select.result
insert_update.result
ipv4_as_ipv6.result
ipv6.result
is_debug_build.require
is_embedded.require
isam.result
join.result
join_crash.result
join_nested.result
join_optimizer.result
join_outer.result Merge from 5.1 to 5.5 2013-01-11 06:36:53 +05:30
join_outer_innodb.result
key.result
key_cache.result
key_diff.result
key_primary.result
keywords.result
kill.result
limit.result
loaddata.result Description: 2012-09-27 02:06:08 +05:30
loaddata_autocom_innodb.result
loadxml.result
locale.result
lock.result
lock_multi.result
lock_multi_bug38499.result
lock_multi_bug38691.result
lock_sync.result
lock_tables_lost_commit.result
log_state.result Bug#14498355: DEPRECATION WARNINGS SHOULD NOT CONTAIN MYSQL VERSION 2012-08-24 10:17:08 +02:00
log_state_bug33693.result
log_tables-big.result
log_tables.result
log_tables_debug.result
log_tables_upgrade.result
long_tmpdir.result
lowercase0.require
lowercase1.require
lowercase2.require
lowercase_fs_off.result
lowercase_mixed_tmpdir.result
lowercase_mixed_tmpdir_innodb.result
lowercase_table.result
lowercase_table2.result
lowercase_table3.result
lowercase_table4.result
lowercase_table_grant.result
lowercase_table_qcache.result
lowercase_utf8.result
lowercase_view.result
mdl_sync.result
merge-big.result
merge.result
merge_innodb.result
merge_mmap.result
merge_recover.result
metadata.result
mix2_myisam.result
mix2_myisam_ucs2.result
multi_statement.result
multi_update.result
multi_update2.result
multi_update_innodb.result
multi_update_tiny_hash.result
myisam-blob.result
myisam-system.result
myisam.result
myisam_crash_before_flush_keys.result
myisam_debug.result
myisampack.result
mysql-bug41486.result
mysql-bug45236.result
mysql.result
mysql_client_test.result
mysql_comments.result
mysql_cp932.result
mysql_embedded.result
mysql_locale_posix.result
mysql_not_windows.result
mysql_plugin.result
mysql_protocols.result
mysql_upgrade.result
mysql_upgrade_ssl.result
mysqladmin.result
mysqlbinlog.result BUG#15891524: RLI_FAKE MODE IS NOT UNSET AFTER BINLOG REPLAY 2012-11-20 12:37:23 +00:00
mysqlbinlog_row_big.result
mysqlcheck.result
mysqld--defaults-file.result
mysqld--help-notwin.result
mysqld--help-win.result
mysqldump-compat.result
mysqldump-max.result
mysqldump-no-binlog.result
mysqldump.result BUG#14117025: UNABLE TO RESTORE DUMP 2013-01-16 18:26:27 +05:30
mysqldump_restore.result
mysqlhotcopy_archive.result
mysqlhotcopy_myisam.result
mysqlshow.result Bug #13113026 INFORMATION_SCHEMA.INNODB_BUFFER_PAGE_LRUFROM 5.6 BACKPORT 2012-07-25 10:48:16 +05:30
mysqlslap.result
mysqltest.result
named_pipe.result
ndb_default_cluster.require
negation_elimination.result
no-threads.result
no_binlog.result
not_embedded.require
not_embedded_server.result
not_ndb.require
not_ndb_default.require
not_openssl.require
not_partition.require
not_partition.result
not_true.require
not_valgrind.require
not_windows.require
null.result
null_key.result
odbc.result
olap.result
one_thread_per_connection.require
openssl_1.result Bug #13115401: -SSL-KEY VALUE IS NOT VALIDATED AND IT ALLOWS INSECURE 2012-08-11 15:52:11 +05:30
optimizer_switch_eng_cond_pushdown1.result
optimizer_switch_eng_cond_pushdown2.result
order_by.result
order_fill_sortbuf.result
outfile.result
outfile_loaddata.result
overflow.result
packet.result
parser.result
parser_bug21114_innodb.result
parser_not_embedded.result
parser_precedence.result
parser_stack.result
partition.result Bug#16274455: CAN NOT ACESS PARTITIONED TABLES WHEN 2013-02-14 17:03:49 +01:00
partition_archive.result
partition_binlog.result
partition_binlog_stmt.result
partition_blackhole.result
partition_bug18198.result
partition_cache.result
partition_charset.result
partition_column.result Bug#16274455: CAN NOT ACESS PARTITIONED TABLES WHEN 2013-02-14 17:03:49 +01:00
partition_column_prune.result
partition_csv.result
partition_datatype.result
partition_debug_sync.result
partition_disabled.result
partition_error.result
partition_federated.result
partition_grant.result
partition_hash.result
partition_innodb.result Bug#16274455: CAN NOT ACESS PARTITIONED TABLES WHEN 2013-02-14 17:03:49 +01:00
partition_innodb_plugin.result
partition_innodb_semi_consistent.result
partition_innodb_stmt.result
partition_key_cache.result
partition_list.result
partition_mgm.result
partition_mgm_err.result Bug#16274455: CAN NOT ACESS PARTITIONED TABLES WHEN 2013-02-14 17:03:49 +01:00
partition_mgm_err2.result
partition_myisam.result Bug#16274455: CAN NOT ACESS PARTITIONED TABLES WHEN 2013-02-14 17:03:49 +01:00
partition_not_blackhole.result
partition_not_windows.result
partition_open_files_limit.result
partition_order.result
partition_pruning.result
partition_range.result
partition_rename_longfilename.result
partition_symlink.result
partition_sync.result
partition_truncate.result
partition_utf8.result
partition_windows.result
perror-win.result
perror.result
plugin.result
plugin_auth.result Bug #14211140: CRASH WHEN GRANTING OR REVOKING PROXY 2012-10-09 18:15:40 +05:30
plugin_auth_qa.result
plugin_auth_qa_1.result
plugin_auth_qa_2.result
plugin_auth_qa_3.result
plugin_load.result
plugin_load_option.result
plugin_not_embedded.result
preload.result
profiling.result
ps.result
ps_1general.result
ps_2myisam.result
ps_3innodb.result
ps_4heap.result
ps_5merge.result
ps_10nestset.result
ps_11bugs.result
ps_ddl.result
ps_ddl1.result
ps_grant.result
ps_not_windows.result
query_cache.result
query_cache_28249.result
query_cache_debug.result
query_cache_disabled.result
query_cache_merge.result
query_cache_notembedded.result
query_cache_ps_no_prot.result
query_cache_ps_ps_prot.result
query_cache_with_views.result
range.result
read_many_rows_innodb.result
read_only.result
read_only_innodb.result
rename.result
renamedb.result
repair.result
replace.result
rollback.result
round.result
row.result
rowid_order_innodb.result
rpl_colSize.result
rpl_extraColmaster_innodb.result
rpl_extraColmaster_myisam.result
rpl_mysqldump_slave.result BUG#16615117 MYSQLDUMP PRODUCES A CHANGE MASTER STATEMENT 2013-04-12 14:18:21 +05:30
schema.result
secure_file_priv_win.result
select.result
select_found.result
select_safe.result
server_id.require
server_id1.require
shm.result
show_check.result Bug#14521864: MYSQL 5.1 TO 5.5 BUGS PARTITIONING 2013-01-30 17:51:52 +01:00
show_profile.result
signal.result
signal_code.result
signal_demo1.result
signal_demo2.result
signal_demo3.result
signal_sqlmode.result
single_delete_update.result
skip_grants.result
skip_log_bin.result
skip_name_resolve.result
slave-running.result
slave-stopped.result
sp-big.result
sp-bugs.result
sp-code.result
sp-destruct.result
sp-dynamic.result
sp-error.result
sp-fib.result
sp-lock.result
sp-no-code.result
sp-prelocking.result
sp-security.result
sp-threads.result
sp-ucs2.result
sp-vars.result
sp.result
sp_gis.result
sp_notembedded.result Merge from 5.1. 2012-10-29 13:06:43 +04:00
sp_stress_case.result
sp_sync.result
sp_trans.result
sp_trans_log.result
sql_mode.result
ssl-big.result
ssl.result
ssl_8k_key.result
ssl_and_innodb.result
ssl_cipher.result
ssl_compress.result
ssl_connect.result
status.result
status2.result
status_bug17954.result
strict.result
strict_autoinc_1myisam.result
strict_autoinc_2innodb.result
strict_autoinc_3heap.result
subselect.result Bug #16076289 : BACKPORT FIX FOR BUG #14786792 TO 5.5 2013-03-18 13:48:53 +05:30
subselect2.result
subselect3.result
subselect4.result
subselect_debug.result
subselect_gis.result
subselect_innodb.result
subselect_notembedded.result
sum_distinct-big.result
sum_distinct.result
symlink.result
synchronization.result
sysdate_is_now.result
system_mysql_db.result
system_mysql_db_refs.result
tablelock.result
tablespace.result
temp_table.result
testdb_only.require
timezone.result
timezone2.result
timezone3.result
timezone4.result
timezone_grant.result
trigger-compat.result
trigger-trans.result
trigger.result
trigger_notembedded.result
true.require
truncate.result
truncate_coverage.result
type_binary.result
type_bit.result
type_bit_innodb.result
type_blob.result manual merge (WL6219) 2012-06-29 14:12:21 +04:00
type_date.result
type_datetime.result
type_decimal.result
type_enum.result
type_float.result
type_nchar.result
type_newdecimal-big.result
type_newdecimal.result
type_ranges.result
type_set.result
type_time.result
type_timestamp.result
type_uint.result
type_varchar.result
type_year.result
udf.result
udf_skip_grants.result
union.result
unsafe_binlog_innodb.result
update.result
upgrade.result
user_limits.result
user_var-binlog.result BUG#15891524: RLI_FAKE MODE IS NOT UNSET AFTER BINLOG REPLAY 2012-11-20 12:37:23 +00:00
user_var.result
varbinary.result
variables-big.result
variables-notembedded.result
variables.result Bug#16084594 USER_VAR ITEM IN 'LOAD FILE QUERY' WAS NOT 2013-01-28 14:58:55 +05:30
variables_community.result
variables_debug.result
view.result
view_alias.result
view_grant.result
wait_timeout.result
warnings.result
warnings_engine_disabled.result
windows.require
windows.result
xa.result
xml.result