php - ROW wise SUM VS COLUMN wise SUM in MySQL -


i have tablea contains following structure

enter image description here

i modified structure tableb below reduce number of rows , category fixed length

enter image description here

assume have 21 lakh data in tablea after modified new structure tableb contains 70k rows only

in case want sum values table,

query1: select sum(val) total tablea;  vs  query2: select sum(cate1+cate2+cate3) total tableb; 

query1 executing faster while comparing query2.

tableb contains less rows while comparing tablea

as of expectation query2 faster query1 fastest one.

help me understand why performance reduced in query2?

mysql optimized speed relational operations. there not effort @ speeding other kinds of operations mysql can perform. cate1+cate2+cate3 legitimate operation, there's nothing particularly relational it.

table1 simpler in terms of relational model of data table2, though table1 has more rows. it's worth noting in passing table1 conforms first normal form table2 not. 3 columns repeating group though it's been made not.

so first normal form in terms of performance (most of time).


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -