[MDEV-4687] impossible where with < operation, but =-5 return one row, same problem occur with UPDATE/SELECT/DELETE Created: 2013-06-20  Updated: 2014-12-13  Resolved: 2013-07-31

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - Aria
Affects Version/s: 10.0.3, 5.5.31, 5.1.67, 5.2.14, 5.3.12
Fix Version/s: 10.0.5, 5.5.33, 5.3.13

Type: Bug Priority: Major
Reporter: roberto spadim Assignee: Sergei Petrunia
Resolution: Fixed Votes: 0
Labels: Aria
Environment:

linux


Attachments: File mdev-4687.dump    

 Description   

hi guys, i got a bug (i think i'm right)
when executing this:
well it's a big table, i will put a link to download
it was 10.0.1 version, but it don't exists anymore in jira

query retuning rows:
SELECT * FROM nf_erro_20130620 WHERE emitente_tipo='j' AND emitente_id=1 AND emitente_propriedade=0 AND nf_serie="3nfe" AND nf=-5

query without rows:
SELECT * FROM nf_erro_20130620 WHERE emitente_tipo='j' AND emitente_id=1 AND emitente_propriedade=0 AND nf_serie="3nfe" AND nf<0

link to table (tar -zcf nf_erro_20130620.tgz nf_erro*)
i removed the link
169.093.860 bytes - the internet link is slow (130KB/s)

or a mysqldump: (mysqldump 19_org nf_erro_20130620 --force > nf_erro_20130620.sql)
i removed the link
112.587.870 bytes - the internet link is slow (130KB/s)-

Note by elenst: use the attachment instead, see the comment: https://mariadb.atlassian.net/browse/MDEV-4687?focusedCommentId=32844&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-32844

EXPLAIN EXTENDED
SELECT * FROM nf_erro_20130620 WHERE emitente_tipo='j' AND emitente_id=1 AND emitente_propriedade=0 AND nf_serie="3nfe" AND nf<0

return a where 0 ?!

show warnings
select `19_org`.`nf_erro_20130620`.`emitente_tipo` AS `emitente_tipo`,`19_org`.`nf_erro_20130620`.`emitente_id` AS `emitente_id`,`19_org`.`nf_erro_20130620`.`emitente_propriedade` AS `emitente_propriedade`,`19_org`.`nf_erro_20130620`.`nf_serie` AS `nf_serie`,`19_org`.`nf_erro_20130620`.`nf` AS `nf`,`19_org`.`nf_erro_20130620`.`id_item` AS `id_item`,`19_org`.`nf_erro_20130620`.`status` AS `status`,`19_org`.`nf_erro_20130620`.`unidade_id` AS `unidade_id`,`19_org`.`nf_erro_20130620`.`lote_tipo` AS `lote_tipo`,`19_org`.`nf_erro_20130620`.`lote_spa` AS `lote_spa`,`19_org`.`nf_erro_20130620`.`oe_tipo` AS `oe_tipo`,`19_org`.`nf_erro_20130620`.`oe` AS `oe`,`19_org`.`nf_erro_20130620`.`oe_seq` AS `oe_seq`,`19_org`.`nf_erro_20130620`.`item_id` AS `item_id`,`19_org`.`nf_erro_20130620`.`item_id_red` AS `item_id_red`,`19_org`.`nf_erro_20130620`.`item_codigo` AS `item_codigo`,`19_org`.`nf_erro_20130620`.`item_desc` AS `item_desc`,`19_org`.`nf_erro_20130620`.`servico` AS `servico`,`19_org`.`nf_erro_20130620`.`documento_auxiliar` AS `documento_auxiliar`,`19_org`.`nf_erro_20130620`.`cfop_id` AS `cfop_id`,`19_org`.`nf_erro_20130620`.`cfop_id_red` AS `cfop_id_red`,`19_org`.`nf_erro_20130620`.`cfop_numero` AS `cfop_numero`,`19_org`.`nf_erro_20130620`.`class_fiscal` AS `class_fiscal`,`19_org`.`nf_erro_20130620`.`sit_trib` AS `sit_trib`,`19_org`.`nf_erro_20130620`.`sit_trib_ipi` AS `sit_trib_ipi`,`19_org`.`nf_erro_20130620`.`sit_trib_pis` AS `sit_trib_pis`,`19_org`.`nf_erro_20130620`.`sit_trib_cofins` AS `sit_trib_cofins`,`19_org`.`nf_erro_20130620`.`sit_trib_iss` AS `sit_trib_iss`,`19_org`.`nf_erro_20130620`.`sit_trib_sn` AS `sit_trib_sn`,`19_org`.`nf_erro_20130620`.`icms_incluir_bc` AS `icms_incluir_bc`,`19_org`.`nf_erro_20130620`.`icms_subst_incluir_bc` AS `icms_subst_incluir_bc`,`19_org`.`nf_erro_20130620`.`ipi_incluir_bc` AS `ipi_incluir_bc`,`19_org`.`nf_erro_20130620`.`pis_inclur_bc` AS `pis_inclur_bc`,`19_org`.`nf_erro_20130620`.`cofins_incluir_bc` AS `cofins_incluir_bc`,`19_org`.`nf_erro_20130620`.`ii_incluir_bc` AS `ii_incluir_bc`,`19_org`.`nf_erro_20130620`.`sn_incluir_bc` AS `sn_incluir_bc`,`19_org`.`nf_erro_20130620`.`un_fat` AS `un_fat`,`19_org`.`nf_erro_20130620`.`quant` AS `quant`,`19_org`.`nf_erro_20130620`.`pecas` AS `pecas`,`19_org`.`nf_erro_20130620`.`pbruto` AS `pbruto`,`19_org`.`nf_erro_20130620`.`pliq` AS `pliq`,`19_org`.`nf_erro_20130620`.`vliq` AS `vliq`,`19_org`.`nf_erro_20130620`.`vbruto` AS `vbruto`,`19_org`.`nf_erro_20130620`.`valor_pauta` AS `valor_pauta`,`19_org`.`nf_erro_20130620`.`valor_pauta_grandeza` AS `valor_pauta_grandeza`,`19_org`.`nf_erro_20130620`.`valor_pauta_grandeza_quant` AS `valor_pauta_grandeza_quant`,`19_org`.`nf_erro_20130620`.`valor_produto_un` AS `valor_produto_un`,`19_org`.`nf_erro_20130620`.`valor_produto_grandeza` AS `valor_produto_grandeza`,`19_org`.`nf_erro_20130620`.`valor_produto_grandeza_quant` AS `valor_produto_grandeza_quant`,`19_org`.`nf_erro_20130620`.`valor_produto_tabela_un` AS `valor_produto_tabela_un`,`19_org`.`nf_erro_20130620`.`valor_produto_total` AS `valor_produto_total`,`19_org`.`nf_erro_20130620`.`valor_frete` AS `valor_frete`,`19_org`.`nf_erro_20130620`.`valor_seguro` AS `valor_seguro`,`19_org`.`nf_erro_20130620`.`valor_outras` AS `valor_outras`,`19_org`.`nf_erro_20130620`.`valor_estimado_impostos` AS `valor_estimado_impostos`,`19_org`.`nf_erro_20130620`.`valor_estimado_impostos_por` AS `valor_estimado_impostos_por`,`19_org`.`nf_erro_20130620`.`desconto` AS `desconto`,`19_org`.`nf_erro_20130620`.`icms_de_aliq` AS `icms_de_aliq`,`19_org`.`nf_erro_20130620`.`icms_de_red` AS `icms_de_red`,`19_org`.`nf_erro_20130620`.`icms_fe_aliq` AS `icms_fe_aliq`,`19_org`.`nf_erro_20130620`.`icms_fe_red` AS `icms_fe_red`,`19_org`.`nf_erro_20130620`.`icms_basecalculo` AS `icms_basecalculo`,`19_org`.`nf_erro_20130620`.`icms_valor` AS `icms_valor`,`19_org`.`nf_erro_20130620`.`icms_subst_ind_convenio` AS `icms_subst_ind_convenio`,`19_org`.`nf_erro_20130620`.`icms_subst_basecalculo` AS `icms_subst_basecalculo`,`19_org`.`nf_erro_20130620`.`icms_subst_valor` AS `icms_subst_valor`,`19_org`.`nf_erro_20130620`.`ipi_aliq` AS `ipi_aliq`,`19_org`.`nf_erro_20130620`.`ipi_red` AS `ipi_red`,`19_org`.`nf_erro_20130620`.`ipi_basecalculo` AS `ipi_basecalculo`,`19_org`.`nf_erro_20130620`.`ipi_valor` AS `ipi_valor`,`19_org`.`nf_erro_20130620`.`iss_aliq` AS `iss_aliq`,`19_org`.`nf_erro_20130620`.`iss_red` AS `iss_red`,`19_org`.`nf_erro_20130620`.`iss_basecalculo` AS `iss_basecalculo`,`19_org`.`nf_erro_20130620`.`iss_valor` AS `iss_valor`,`19_org`.`nf_erro_20130620`.`pis_aliq` AS `pis_aliq`,`19_org`.`nf_erro_20130620`.`pis_red` AS `pis_red`,`19_org`.`nf_erro_20130620`.`pis_basecalculo` AS `pis_basecalculo`,`19_org`.`nf_erro_20130620`.`pis_valor` AS `pis_valor`,`19_org`.`nf_erro_20130620`.`cofins_aliq` AS `cofins_aliq`,`19_org`.`nf_erro_20130620`.`cofins_red` AS `cofins_red`,`19_org`.`nf_erro_20130620`.`cofins_basecalculo` AS `cofins_basecalculo`,`19_org`.`nf_erro_20130620`.`cofins_valor` AS `cofins_valor`,`19_org`.`nf_erro_20130620`.`funrural_aliq` AS `funrural_aliq`,`19_org`.`nf_erro_20130620`.`funrural_red` AS `funrural_red`,`19_org`.`nf_erro_20130620`.`funrural_basecalculo` AS `funrural_basecalculo`,`19_org`.`nf_erro_20130620`.`funrural_valor` AS `funrural_valor`,`19_org`.`nf_erro_20130620`.`sn_aliq` AS `sn_aliq`,`19_org`.`nf_erro_20130620`.`sn_red` AS `sn_red`,`19_org`.`nf_erro_20130620`.`sn_basecalculo` AS `sn_basecalculo`,`19_org`.`nf_erro_20130620`.`sn_valor` AS `sn_valor`,`19_org`.`nf_erro_20130620`.`cide_aliq` AS `cide_aliq`,`19_org`.`nf_erro_20130620`.`cide_red` AS `cide_red`,`19_org`.`nf_erro_20130620`.`cide_basecalculo` AS `cide_basecalculo`,`19_org`.`nf_erro_20130620`.`cide_valor` AS `cide_valor`,`19_org`.`nf_erro_20130620`.`csll_aliq` AS `csll_aliq`,`19_org`.`nf_erro_20130620`.`csll_red` AS `csll_red`,`19_org`.`nf_erro_20130620`.`csll_basecalculo` AS `csll_basecalculo`,`19_org`.`nf_erro_20130620`.`csll_valor` AS `csll_valor`,`19_org`.`nf_erro_20130620`.`sit_trib_csll` AS `sit_trib_csll`,`19_org`.`nf_erro_20130620`.`inss_aliq` AS `inss_aliq`,`19_org`.`nf_erro_20130620`.`inss_red` AS `inss_red`,`19_org`.`nf_erro_20130620`.`inss_basecalculo` AS `inss_basecalculo`,`19_org`.`nf_erro_20130620`.`inss_valor` AS `inss_valor`,`19_org`.`nf_erro_20130620`.`sit_trib_inss` AS `sit_trib_inss`,`19_org`.`nf_erro_20130620`.`ir_aliq` AS `ir_aliq`,`19_org`.`nf_erro_20130620`.`ir_red` AS `ir_red`,`19_org`.`nf_erro_20130620`.`ir_basecalculo` AS `ir_basecalculo`,`19_org`.`nf_erro_20130620`.`ir_valor` AS `ir_valor`,`19_org`.`nf_erro_20130620`.`sit_trib_ir` AS `sit_trib_ir`,`19_org`.`nf_erro_20130620`.`ii_aliq` AS `ii_aliq`,`19_org`.`nf_erro_20130620`.`ii_red` AS `ii_red`,`19_org`.`nf_erro_20130620`.`ii_basecalculo` AS `ii_basecalculo`,`19_org`.`nf_erro_20130620`.`ii_valor` AS `ii_valor`,`19_org`.`nf_erro_20130620`.`sit_trib_ii` AS `sit_trib_ii`,`19_org`.`nf_erro_20130620`.`numero_pedido_compra` AS `numero_pedido_compra`,`19_org`.`nf_erro_20130620`.`numero_item_pedido` AS `numero_item_pedido`,`19_org`.`nf_erro_20130620`.`obs_item` AS `obs_item`,`19_org`.`nf_erro_20130620`.`quant_devolvida` AS `quant_devolvida`,`19_org`.`nf_erro_20130620`.`pecas_devolvida` AS `pecas_devolvida`,`19_org`.`nf_erro_20130620`.`pbruto_devolvida` AS `pbruto_devolvida`,`19_org`.`nf_erro_20130620`.`pliq_devolvida` AS `pliq_devolvida`,`19_org`.`nf_erro_20130620`.`vliq_devolvida` AS `vliq_devolvida`,`19_org`.`nf_erro_20130620`.`vbruto_devolvida` AS `vbruto_devolvida`,`19_org`.`nf_erro_20130620`.`ii_anterior_un` AS `ii_anterior_un`,`19_org`.`nf_erro_20130620`.`ipi_anterior_un` AS `ipi_anterior_un`,`19_org`.`nf_erro_20130620`.`pis_anterior_un` AS `pis_anterior_un`,`19_org`.`nf_erro_20130620`.`cofins_anterior_un` AS `cofins_anterior_un` from `19_org`.`nf_erro_20130620` where 0



 Comments   
Comment by roberto spadim [ 2013-06-20 ]

analyze table nf_erro_20130620 ;
don't help here...

Comment by roberto spadim [ 2013-06-20 ]

SELECT
*
FROM nf_erro_20130620 WHERE
emitente_tipo='j' AND emitente_id=1 AND emitente_propriedade=0 AND
nf_serie="3nfe" AND
nf>-100000000000000 and nf<0
with a nf> -100000000000000000 worked
maybe nf<0 have some problem in MIN_LIMIT inside opt_range.cc?

Comment by Elena Stepanova [ 2013-06-20 ]

Hi Roberto,

Did you attempt to edit the dump manually?
It looks tampered with.

Please send SHOW CREATE TABLE exactly like it is in the client, without any editing.

Comment by Elena Stepanova [ 2013-06-21 ]

Roberto,

If you paste the EXPLAIN (as you did updating the description), please paste ALL of it, not just fragments you find surprising.
And please provide the information requested above, otherwise I'll have to close the bug as incomplete, because your dump won't even load.

Please also clarify what you mean by 'affected version 10.0.4' – where you got it, how you built it.

Comment by roberto spadim [ 2013-06-21 ]

sorry about version, i was editing the jira report but it didn't allowed the 10.0.1 and there's no 10.0.3 anymore, i put 10.0.4, i'm testing with 10.0.3 now, but i think it will have the same error
how to reproduce:
download the sql.tgz version (2GB sql file)
run the script
and run the query with explain
it will return impossible WHERE
and the extended explain show a query with WHERE 0

it should result in one row, the same using nf=-5
but if you do
nf<0 and nf >-1000 it works
i think that nf<0 isn't setting the lower limit and maybe thinking that the field is a unsigned value?! i don't know why it return no rows yet

Comment by Elena Stepanova [ 2013-06-21 ]

Roberto,

Once again, please provide full output of SHOW CREATE TABLE.
And please answer the question, Did you attempt to edit the dump manually?

Comment by roberto spadim [ 2013-06-21 ]

just one minute i will get the create table, the server is down now, or the internet link is slow

Comment by roberto spadim [ 2013-06-21 ]

show create table:
CREATE TABLE `nf_erro_20130620` (
`emitente_tipo` enum('f','j') NOT NULL DEFAULT 'f',
`emitente_id` int(10) unsigned NOT NULL DEFAULT '0',
`emitente_propriedade` tinyint(3) unsigned NOT NULL DEFAULT '0',
`nf_serie` char(5) NOT NULL DEFAULT 'A',
`nf` int(11) NOT NULL DEFAULT '0',
`id_item` int(11) NOT NULL DEFAULT '0',
`status` enum('ok','c','d','nf','i') NOT NULL DEFAULT 'ok',
`unidade_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
`lote_tipo` enum('v','c') NOT NULL DEFAULT 'v',
`lote_spa` decimal(12,1) NOT NULL DEFAULT '0.0',
`oe_tipo` enum('oe','fec') NOT NULL DEFAULT 'oe',
`oe` bigint(20) NOT NULL DEFAULT '0',
`oe_seq` mediumint(9) NOT NULL DEFAULT '0',
`item_id` smallint(5) unsigned NOT NULL DEFAULT '0',
`item_id_red` mediumint(9) NOT NULL DEFAULT '0',
`item_codigo` char(30) NOT NULL DEFAULT '0',
`item_desc` char(100) NOT NULL DEFAULT '',
`servico` enum('Y','N') NOT NULL DEFAULT 'N',
`documento_auxiliar` enum('Y','N') NOT NULL DEFAULT 'N',
`cfop_id` tinyint(3) unsigned NOT NULL DEFAULT '0',
`cfop_id_red` int(11) NOT NULL DEFAULT '0',
`cfop_numero` varchar(10) NOT NULL DEFAULT '',
`class_fiscal` char(20) NOT NULL DEFAULT '',
`sit_trib` char(3) NOT NULL DEFAULT '',
`sit_trib_ipi` char(3) NOT NULL DEFAULT '',
`sit_trib_pis` char(3) NOT NULL DEFAULT '',
`sit_trib_cofins` char(3) NOT NULL DEFAULT '',
`sit_trib_iss` varchar(1) NOT NULL DEFAULT '',
`sit_trib_sn` varchar(4) NOT NULL DEFAULT '',
`icms_incluir_bc` varchar(5) NOT NULL DEFAULT '',
`icms_subst_incluir_bc` varchar(5) NOT NULL DEFAULT '',
`ipi_incluir_bc` varchar(5) NOT NULL DEFAULT '',
`pis_inclur_bc` varchar(5) NOT NULL DEFAULT '',
`cofins_incluir_bc` varchar(5) NOT NULL DEFAULT '',
`ii_incluir_bc` varchar(5) NOT NULL DEFAULT '',
`sn_incluir_bc` varchar(5) NOT NULL DEFAULT '',
`un_fat` char(5) NOT NULL DEFAULT '',
`quant` decimal(17,5) NOT NULL DEFAULT '0.00000',
`pecas` decimal(17,5) NOT NULL DEFAULT '0.00000',
`pbruto` decimal(17,5) NOT NULL DEFAULT '0.00000',
`pliq` decimal(17,5) NOT NULL DEFAULT '0.00000',
`vliq` decimal(17,5) NOT NULL DEFAULT '0.00000',
`vbruto` decimal(17,5) NOT NULL DEFAULT '0.00000',
`valor_pauta` decimal(17,5) NOT NULL DEFAULT '0.00000',
`valor_pauta_grandeza` enum('un','up','pl','pb','@pl','@pb','vl','vb') NOT NULL DEFAULT 'un',
`valor_pauta_grandeza_quant` decimal(17,5) NOT NULL DEFAULT '1.00000',
`valor_produto_un` decimal(17,5) NOT NULL DEFAULT '0.00000',
`valor_produto_grandeza` enum('un','up','pl','pb','@pl','@pb','vl','vb') NOT NULL DEFAULT 'un',
`valor_produto_grandeza_quant` decimal(10,5) NOT NULL DEFAULT '1.00000',
`valor_produto_tabela_un` decimal(17,5) NOT NULL DEFAULT '0.00000',
`valor_produto_total` decimal(17,5) NOT NULL DEFAULT '0.00000',
`valor_frete` decimal(17,5) NOT NULL DEFAULT '0.00000',
`valor_seguro` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`valor_outras` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`valor_estimado_impostos` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000' COMMENT 'lei da transparencia',
`valor_estimado_impostos_por` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`desconto` decimal(17,5) NOT NULL DEFAULT '0.00000',
`icms_de_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`icms_de_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`icms_fe_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`icms_fe_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`icms_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`icms_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`icms_subst_ind_convenio` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`icms_subst_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`icms_subst_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`ipi_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`ipi_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`ipi_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`ipi_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`iss_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`iss_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`iss_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`iss_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`pis_aliq` decimal(10,5) NOT NULL DEFAULT '0.00000',
`pis_red` decimal(10,5) NOT NULL DEFAULT '0.00000',
`pis_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`pis_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`cofins_aliq` decimal(10,5) NOT NULL DEFAULT '0.00000',
`cofins_red` decimal(10,5) NOT NULL DEFAULT '0.00000',
`cofins_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`cofins_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`funrural_aliq` decimal(10,5) NOT NULL DEFAULT '0.00000',
`funrural_red` decimal(10,5) NOT NULL DEFAULT '0.00000',
`funrural_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`funrural_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`sn_aliq` decimal(10,5) NOT NULL DEFAULT '0.00000',
`sn_red` decimal(10,5) NOT NULL DEFAULT '0.00000',
`sn_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`sn_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`cide_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`cide_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`cide_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`cide_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`csll_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`csll_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`csll_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`csll_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`sit_trib_csll` varchar(4) NOT NULL DEFAULT '',
`inss_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`inss_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`inss_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`inss_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`sit_trib_inss` varchar(4) NOT NULL DEFAULT '',
`ir_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`ir_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`ir_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`ir_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`sit_trib_ir` varchar(4) NOT NULL DEFAULT '',
`ii_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`ii_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`ii_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`ii_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`sit_trib_ii` varchar(4) NOT NULL DEFAULT '',
`numero_pedido_compra` varchar(25) NOT NULL DEFAULT '',
`numero_item_pedido` varchar(25) NOT NULL DEFAULT '',
`obs_item` varchar(255) NOT NULL DEFAULT '',
`quant_devolvida` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`pecas_devolvida` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`pbruto_devolvida` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`pliq_devolvida` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`vliq_devolvida` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`vbruto_devolvida` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`ii_anterior_un` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`ipi_anterior_un` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`pis_anterior_un` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`cofins_anterior_un` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
PRIMARY KEY (`emitente_tipo`,`emitente_id`,`emitente_propriedade`,`nf_serie`,`nf`,`id_item`),
KEY `spamov` (`unidade_id`,`lote_tipo`,`lote_spa`,`item_id`,`item_id_red`),
KEY `item_id` (`emitente_tipo`,`emitente_id`,`emitente_propriedade`,`nf_serie`,`nf`,`item_id`,`item_id_red`)
) ENGINE=Aria DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (nf)
(PARTITION s0 VALUES LESS THAN (100000) ENGINE = Aria,
PARTITION s1 VALUES LESS THAN (450000) ENGINE = Aria,
PARTITION s2 VALUES LESS THAN (800000) ENGINE = Aria,
PARTITION s3 VALUES LESS THAN MAXVALUE ENGINE = Aria) */

Comment by roberto spadim [ 2013-06-21 ]

no i didn't changed the dump

Comment by roberto spadim [ 2013-06-21 ]

hum the dump shows:
)/*! engine=Aria partitioned */;
i will check mysql_dump verision

Comment by roberto spadim [ 2013-06-21 ]

sorry server was using a old version of mysql 5.0.60 mysqldump
/usr/bin/mysqldump --version
mysqldump Ver 10.11 Distrib 5.0.60, for unknown-linux-gnu (x86_64)

Comment by roberto spadim [ 2013-06-21 ]

elena, i updated the mysqldump and add a new file to download
i'm running in 10.0.3 and it didn't return the row too

Comment by Elena Stepanova [ 2013-06-21 ]

Thank you.

Comment by roberto spadim [ 2013-06-21 ]

i will do some other works, but i think it's something in opt_range at partition prune, i will turn off partition prune and test

Comment by roberto spadim [ 2013-06-21 ]

no partition prune switch in optimizer_switch?

Comment by Elena Stepanova [ 2013-06-21 ]

Attached a reduced dump.
Partitioning is irrelevant.
Aria seems important (not reproducible with same dump, but MyISAM).

To reproduce, load the dump and execute

SELECT * FROM test.t7 WHERE emitente_tipo='j' AND emitente_id=1 AND emitente_propriedade=0 AND nf_serie='3nfe' AND nf < 0 ;

Comment by roberto spadim [ 2013-06-21 ]

nice elena, thanks a lot!

Comment by roberto spadim [ 2013-07-25 ]

any idea about a patch? this make aria useless to me

Comment by Sergei Petrunia [ 2013-07-25 ]

Let's see...

  1. Try on Aria table
    MariaDB [j81]> explain SELECT * FROM t7 WHERE emitente_tipo='j' AND emitente_id=1 AND emitente_propriedade=0 AND nf_serie='3nfe' AND nf < 0 ;
    -------------------------------------------------------------------------------------------------------------+
    id select_type table type possible_keys key key_len ref rows Extra

    -------------------------------------------------------------------------------------------------------------+

    1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables

    -------------------------------------------------------------------------------------------------------------+

  1. Try on a MyISAM table with the same structure/data:
    MariaDB [j81]> explain SELECT * FROM t7m WHERE emitente_tipo='j' AND emitente_id=1 AND emitente_propriedade=0 AND nf_serie='3nfe' AND nf < 0 ;
    -------------------------------------------------------------------------------------+
    id select_type table type possible_keys key key_len ref rows Extra

    -------------------------------------------------------------------------------------+

    1 SIMPLE t7m range PRIMARY,item_id item_id 15 NULL 1 Using index condition

    -------------------------------------------------------------------------------------+
    1 row in set (0.00 sec)

Comment by Sergei Petrunia [ 2013-07-25 ]

Debugging, I see that in case of Aria, range analyzer has returned that "impossible range".
ha_maria::records_in_range (this=0x7fff9402f868, inx=0, min_key=0x7fffc87c41b0, max_key=0x7fffc87c41d0)= 0

Looking at key#0 definition and WHERE:

PRIMARY KEY (`emitente_tipo`,`emitente_id`,`emitente_propriedade`,`nf_serie`,`nf`,`id_item`),

emitente_tipo='j' – pk1
AND emitente_id=1 – pk2
AND emitente_propriedade=0 – pk3
AND nf_serie="3nfe" – pk4
AND nf<0 – pk5

  1. Note that there is no restriction for the last PK component, id_item.
Comment by Sergei Petrunia [ 2013-07-25 ]

The problem seems to be in the ha_maria::records_in_range(). If make that function return 10 (in gdb), the query returns correct result.

Comment by roberto spadim [ 2013-07-25 ]

i didn't tested aria without page file format... (similar to myisam format right?)

Comment by roberto spadim [ 2013-07-25 ]

after a:
alter table t7 engine=aria row_format=page

or after a:
repair table t7

the query runs ok with two rows

(I'm using the elena dump file)

Comment by roberto spadim [ 2013-07-26 ]

Using create table with " row_format=dynamic" give the "same error" (maybe the statistics of aria is wrong)
after a repair or alter table, results get back again...
i think it's something at index creation and statistics update when we run inserts

Comment by roberto spadim [ 2013-07-26 ]

running create table without index, it works nice (but don't use index...)
getting back to my last comment, i'm near sure that index statistics is corrupted while running insert
example of create table without index:

CREATE TABLE `t7` (
`emitente_tipo` enum('f','j') NOT NULL DEFAULT 'f',
`emitente_id` int(10) unsigned NOT NULL DEFAULT '0',
`emitente_propriedade` tinyint(3) unsigned NOT NULL DEFAULT '0',
`nf_serie` char(5) NOT NULL DEFAULT 'A',
`nf` int(11) NOT NULL DEFAULT '0',
`id_item` int(11) NOT NULL DEFAULT '0',
`status` enum('ok','c','d','nf','i') NOT NULL DEFAULT 'ok',
`unidade_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
`lote_tipo` enum('v','c') NOT NULL DEFAULT 'v',
`lote_spa` decimal(12,1) NOT NULL DEFAULT '0.0',
`oe_tipo` enum('oe','fec') NOT NULL DEFAULT 'oe',
`oe` bigint(20) NOT NULL DEFAULT '0',
`oe_seq` mediumint(9) NOT NULL DEFAULT '0',
`item_id` smallint(5) unsigned NOT NULL DEFAULT '0',
`item_id_red` mediumint(9) NOT NULL DEFAULT '0',
`item_codigo` char(30) NOT NULL DEFAULT '0',
`item_desc` char(100) NOT NULL DEFAULT '',
`servico` enum('Y','N') NOT NULL DEFAULT 'N',
`documento_auxiliar` enum('Y','N') NOT NULL DEFAULT 'N',
`cfop_id` tinyint(3) unsigned NOT NULL DEFAULT '0',
`cfop_id_red` int(11) NOT NULL DEFAULT '0',
`cfop_numero` varchar(10) NOT NULL DEFAULT '',
`class_fiscal` char(20) NOT NULL DEFAULT '',
`sit_trib` char(3) NOT NULL DEFAULT '',
`sit_trib_ipi` char(3) NOT NULL DEFAULT '',
`sit_trib_pis` char(3) NOT NULL DEFAULT '',
`sit_trib_cofins` char(3) NOT NULL DEFAULT '',
`sit_trib_iss` varchar(1) NOT NULL DEFAULT '',
`sit_trib_sn` varchar(4) NOT NULL DEFAULT '',
`icms_incluir_bc` varchar(5) NOT NULL DEFAULT '',
`icms_subst_incluir_bc` varchar(5) NOT NULL DEFAULT '',
`ipi_incluir_bc` varchar(5) NOT NULL DEFAULT '',
`pis_inclur_bc` varchar(5) NOT NULL DEFAULT '',
`cofins_incluir_bc` varchar(5) NOT NULL DEFAULT '',
`ii_incluir_bc` varchar(5) NOT NULL DEFAULT '',
`sn_incluir_bc` varchar(5) NOT NULL DEFAULT '',
`un_fat` char(5) NOT NULL DEFAULT '',
`quant` decimal(17,5) NOT NULL DEFAULT '0.00000',
`pecas` decimal(17,5) NOT NULL DEFAULT '0.00000',
`pbruto` decimal(17,5) NOT NULL DEFAULT '0.00000',
`pliq` decimal(17,5) NOT NULL DEFAULT '0.00000',
`vliq` decimal(17,5) NOT NULL DEFAULT '0.00000',
`vbruto` decimal(17,5) NOT NULL DEFAULT '0.00000',
`valor_pauta` decimal(17,5) NOT NULL DEFAULT '0.00000',
`valor_pauta_grandeza` enum('un','up','pl','pb','@pl','@pb','vl','vb') NOT NULL DEFAULT 'un',
`valor_pauta_grandeza_quant` decimal(17,5) NOT NULL DEFAULT '1.00000',
`valor_produto_un` decimal(17,5) NOT NULL DEFAULT '0.00000',
`valor_produto_grandeza` enum('un','up','pl','pb','@pl','@pb','vl','vb') NOT NULL DEFAULT 'un',
`valor_produto_grandeza_quant` decimal(10,5) NOT NULL DEFAULT '1.00000',
`valor_produto_tabela_un` decimal(17,5) NOT NULL DEFAULT '0.00000',
`valor_produto_total` decimal(17,5) NOT NULL DEFAULT '0.00000',
`valor_frete` decimal(17,5) NOT NULL DEFAULT '0.00000',
`valor_seguro` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`valor_outras` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`valor_estimado_impostos` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000' COMMENT 'lei da transparencia',
`valor_estimado_impostos_por` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`desconto` decimal(17,5) NOT NULL DEFAULT '0.00000',
`icms_de_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`icms_de_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`icms_fe_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`icms_fe_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`icms_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`icms_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`icms_subst_ind_convenio` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`icms_subst_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`icms_subst_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`ipi_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`ipi_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`ipi_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`ipi_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`iss_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`iss_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`iss_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`iss_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`pis_aliq` decimal(10,5) NOT NULL DEFAULT '0.00000',
`pis_red` decimal(10,5) NOT NULL DEFAULT '0.00000',
`pis_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`pis_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`cofins_aliq` decimal(10,5) NOT NULL DEFAULT '0.00000',
`cofins_red` decimal(10,5) NOT NULL DEFAULT '0.00000',
`cofins_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`cofins_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`funrural_aliq` decimal(10,5) NOT NULL DEFAULT '0.00000',
`funrural_red` decimal(10,5) NOT NULL DEFAULT '0.00000',
`funrural_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`funrural_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`sn_aliq` decimal(10,5) NOT NULL DEFAULT '0.00000',
`sn_red` decimal(10,5) NOT NULL DEFAULT '0.00000',
`sn_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`sn_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`cide_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`cide_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`cide_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`cide_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`csll_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`csll_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`csll_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`csll_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`sit_trib_csll` varchar(4) NOT NULL DEFAULT '',
`inss_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`inss_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`inss_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`inss_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`sit_trib_inss` varchar(4) NOT NULL DEFAULT '',
`ir_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`ir_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`ir_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`ir_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`sit_trib_ir` varchar(4) NOT NULL DEFAULT '',
`ii_aliq` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`ii_red` decimal(10,7) NOT NULL DEFAULT '0.0000000',
`ii_basecalculo` decimal(17,5) NOT NULL DEFAULT '0.00000',
`ii_valor` decimal(17,5) NOT NULL DEFAULT '0.00000',
`sit_trib_ii` varchar(4) NOT NULL DEFAULT '',
`numero_pedido_compra` varchar(25) NOT NULL DEFAULT '',
`numero_item_pedido` varchar(25) NOT NULL DEFAULT '',
`obs_item` varchar(255) NOT NULL DEFAULT '',
`quant_devolvida` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`pecas_devolvida` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`pbruto_devolvida` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`pliq_devolvida` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`vliq_devolvida` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`vbruto_devolvida` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`ii_anterior_un` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`ipi_anterior_un` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`pis_anterior_un` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000',
`cofins_anterior_un` decimal(17,5) unsigned NOT NULL DEFAULT '0.00000'
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1;

Comment by Sergei Petrunia [ 2013-07-26 ]

Inside maria_records_in_range (info=0x7fff94021cb0, inx=0, min_key=0x7fffc87c41c0, max_key=0x7fffc87c41e0) at /home/psergey/dev2/5.5/storage/maria/ma_range.c:101

we have:

(gdb) print start_pos
$122 = 652
(gdb) print end_pos
$123 = 578

That is, it thinks that "start_pos > end_pos" , in other words, lower_endpoint > upper_endpoint, and returns 0.

is incorrect.

Comment by Sergei Petrunia [ 2013-07-26 ]

Relevant part of DDL and query:

CREATE TABLE `t7` (
`emitente_tipo` enum('f','j') NOT NULL DEFAULT 'f',
`emitente_id` int(10) unsigned NOT NULL DEFAULT '0',
`emitente_propriedade` tinyint(3) unsigned NOT NULL DEFAULT '0',
`nf_serie` char(5) NOT NULL DEFAULT 'A',
`nf` int(11) NOT NULL DEFAULT '0',
`id_item` int(11) NOT NULL DEFAULT '0',
...
PRIMARY KEY (`emitente_tipo`,`emitente_id`,`emitente_propriedade`,`nf_serie`,`nf`,`id_item`),
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1

select nf,id_item from t7 where emitente_tipo='j' AND emitente_id=1 AND emitente_propriedade=0 AND nf_serie="3nfe" AND nf<0;

in mysqld.trace, _ma_record_pos() prints range endpoints. They are

Key: "2-1-0-3nfe "

Key: "2-1-0-3nfe -0"

The endpoints seem to be correct.

Comment by Sergei Petrunia [ 2013-07-26 ]

I am debugging _ma_search_pos() for both start_pos and end_pos.

In both cases, they determine key position on the root page here:

flag= (*keyinfo->bin_search)(key, &page, nextflag, &keypos,
info->lastkey_buff, &after_key);
keynr= _ma_keynr(&page, keypos, &max_keynr);

for start_pos:
keynr=2 max_keynr=5 page.node=5 flag=0
for end_pos:
keynr=2 max_keynr=5 page.node=5 flag=1

for start_pos:
we calculate offset=1.0
andd return (keynr+1)/(max_keynr+1) = 0.5

for end_pos:
_ma_search_pos calls _ma_search_pos() for a leaf node.
the second call returns offset=0.65900383141762453

This way, we get the situationm where start_pos > end_pos.

Because they've found the same key on the root node and then
start_pos got offset=1.0, while end_pos got offset=0.65900383141762453

Comment by Sergei Petrunia [ 2013-07-26 ]

Committed a patch.

Comment by Sergei Petrunia [ 2013-07-26 ]

http://lists.askmonty.org/pipermail/commits/2013-July/005132.html

Comment by roberto spadim [ 2013-07-26 ]

sergei, a doubt ...
why a repair or an alter make this same query work? repair rewrite the index? and the optimizer runs differntly?

Comment by roberto spadim [ 2013-07-26 ]

SAME PROBLEM BUT WITH UPDATE AND DELETE...

DELETE FROM t7
WHERE emitente_tipo='j' AND emitente_id=1 AND emitente_propriedade=0 AND nf_serie='3nfe' AND nf < 0;
/* Affected rows: 0 Registros encontrados: 0 Avisos: 0 Duração de 1 query: 0,047 sec. */

update t7
set emitente_propriedade=1
WHERE emitente_tipo='j' AND emitente_id=1 AND emitente_propriedade=0 AND nf_serie='3nfe' AND nf < 0;
/* Affected rows: 0 Registros encontrados: 0 Avisos: 0 Duração de 1 query: 0,046 sec. */

Comment by roberto spadim [ 2013-07-26 ]

with patch, UPDATE/SELECT/DELETE works without problems

Comment by roberto spadim [ 2013-07-30 ]

could this be implemented in near next releases?

Comment by Sergei Petrunia [ 2013-07-31 ]

Roberto,

You have reported that the fix worked for you (thanks!)
Elena also ran tests and found no problem.

We intend to include the fix in the next 5.5 release.

Comment by Sergei Petrunia [ 2013-07-31 ]

Pushed into 5.5 tree

Comment by roberto spadim [ 2013-07-31 ]

nice sergei! i tested with 10.0.3 and this worked fine too
i don't use <5.5 maybe someone could test...

thanks again =]

Comment by roberto spadim [ 2013-08-16 ]

PLEASE PUT THIS IN 10.0.4 VERSION =]

Comment by Sergei Golubchik [ 2013-08-16 ]

I'm afraid it's too late to do a new 5.5->10.0 merge now. Remember, 10.0.4 is an alpha release, it's main feature is 5.6 merge. The goal of 10.0.4 release is to get the new features out so that users could try them out.

In about a month we expect to have 10.0.5 release that will include this bug fix.

Comment by roberto spadim [ 2013-08-16 ]

ok no problem, i used the same patch for 10.0.3 without changes, and it worked, if possible put this as soon as possible, recompiling sometimes is a problem, the binary is easier to install =] thanks !

Generated at Thu Feb 08 06:58:22 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.