sql - mySQL (and MSSQL), using both indexed and non-indexed columns in where clause -
the database use mysql maybe later mssql.
my questing how mysql , mssql takes care indexed , nonindexed columns.
lets have simple table this:
*table_id -auto increase. id, indexed.
*table_user_id -every user has unique id indexed
*table_somotherid -some data..
*....
lets have lot!! of rows in table, number of rows every user add table small (10-100)
and want find 1 o few specific rows in table. row or rows specific user(indexed column).
if use following clause: ..... table_user_id= 'someid' , table_someotherid='anothervalue'.
will database first search indexed columns, , search "anothervalue" inside of rows, or how database handle this?
i guess database increase lot if have index every column in tables.. think, enough index columns decrease number of rows ten maybe hundred?
database optimizers work on cost basis on indexes looking @ possible indexes use based on query. in specific case see 2 columns - table_user_id index , someotherid without index. if have 10-100 rows per userid cost of index low , used. because cardinality high , db can read few rows needs , not touch other rows every other user not interested in. however, if cost use index high (very few unique userids , many entries per user) might more efficient not use index , scan whole table prevent random seeking action jumps around table grabbing rows based on index.
once picks index db grabs rows match index (10 100 in case) , try match them against other criteria searching rows someotherid='anothervalue'
Comments
Post a Comment