Questions
14 of 15
1What are the main categories of data types available in MySQL?
2What is the difference between CHAR and VARCHAR data types?
3Which data type would you use to store dates and times in MySQL?
4What is the difference between INT, FLOAT, and DECIMAL data types?
5What is the use of the TEXT and BLOB data types, and how are they different from VARCHAR?
6How does MySQL handle precision and scale in DECIMAL(M, D) columns internally, and how do these differ from FLOAT and DOUBLE in terms of storage and accuracy?
7When storing time zone–aware data, what are the differences in behavior and use cases between DATETIME, TIMESTAMP, and CONVERT_TZ() in MySQL?
8If you define a VARCHAR(255) column with utf8mb4 encoding, how does MySQL calculate the maximum possible storage size for that column, and how does it differ from CHAR(255)?
9What are the advantages and limitations of using ENUM and SET data types in terms of performance, flexibility, and schema evolution?
10Explain how MySQL internally stores and sorts values of type BLOB and TEXT. What happens when you try to index a TEXT column?
11How do signed and unsigned integer types affect query results, index usage, and storage size? Can you demonstrate an example where overflow behavior differs?
12In what scenarios would using a JSON column be preferable to a normalized table structure, and what are the internal storage and indexing implications of JSON in MySQL 8.0?
13How does MySQL’s BIT(M) type differ from BOOLEAN, TINYINT(1), and binary string types (BINARY, VARBINARY) in terms of storage, representation, and retrieval?
14If you define a composite index on multiple columns of different data types (e.g., INT, VARCHAR, and DATE), how do the internal data type differences influence sorting, comparisons, and index efficiency?
15What are the practical implications of using CHAR vs VARCHAR for columns in InnoDB tables with varying row lengths and frequent updates? How does this choice affect row fragmentation and performance?
14 / 15

If you define a composite index on multiple columns of different data types (e.g., INT, VARCHAR, and DATE), how do the internal data type differences influence sorting, comparisons, and index efficiency?

How Data Types Affect Composite Index Sorting, Comparison & Efficiency

In a composite (multi-column) index, MySQL stores and sorts values in left-to-right order based on the data type of each column. Different data types influence how comparisons are performed, how the B-Tree is organized, and how efficiently the index can be used.

How Data Types Affect Sorting in Composite Indexes
  1. 1

    MySQL sorts composite index entries lexicographically (column1 → column2 → column3...).

  2. 2

    Numeric types (INT, BIGINT) sort using binary integer comparison — fast and CPU-efficient.

  3. 3

    VARCHAR sorts based on collation (case sensitivity, accent rules), making comparisons slower.

  4. 4

    DATE and DATETIME sort using chronological numeric ordering, which is efficient.

How Data Type Differences Affect Comparisons
  1. 1

    INT comparisons are exact, fixed-length, and fast since values are stored in binary.

  2. 2

    VARCHAR comparisons depend on collation → may require multi-byte comparison and normalization.

  3. 3

    DATE values are compared as integers representing YYYYMMDD → consistent and fast.

  4. 4

    Mixed-type comparisons (e.g., INT vs VARCHAR literals) cause implicit type casts and reduce index usage.

Impact on Index Efficiency
  1. 1

    Composite index efficiency is highest when the most selective, fixed-length, and simple types (like INT) appear first.

  2. 2

    VARCHAR columns reduce index efficiency because collation-based comparisons require more CPU.

  3. 3

    Using large VARCHAR columns increases index size → fewer index entries per page → more I/O.

  4. 4

    DATE columns are compact (3 bytes) and index-friendly.

Example: Composite Index (INT, VARCHAR, DATE)
  1. 1

    Index structure: INDEX (user_id INT, status VARCHAR, created_at DATE).

  2. 2

    MySQL first groups all rows by user_id (fast binary integer ordering).

  3. 3

    Within each user_id, rows are sorted by status using collation rules.

  4. 4

    Finally, for each status group, rows are sorted by created_at chronologically.

Query Efficiency Example
Inefficient Query Example
Key Behaviors to Know
  1. 1

    Index can only be used left-to-right (prefix rule).

  2. 2

    Data types with variable-length or collation overhead slow down comparisons.

  3. 3

    The order of columns in composite indexes should prioritize: high selectivity → fixed-length → frequently filtered columns.

  4. 4

    Implicit type conversion prevents index usage and forces full scans.