skip to content

One row of a narrow fixed-width whole-number column is assigned an out-of-range value. What happens to the whole column?

level: middleimportance: should knowfreq 54%

answer

  1. a column is one buffer
  2. no per-row type to fall back on
  3. refuse, widen, hold anything, or coerce
  4. coercion changes the value silently

basics

~20 s

The change cannot be local: a column is one buffer in one representation, with no per-row type. Four outcomes are real - refusal, the column widens, it falls back to holding anything, or the value is coerced to fit.

solid answer

~50 s

A narrow fixed-width whole-number column gives every row the same declared number of bytes, and a value outside that range simply cannot be represented in it. There is no per-row type to fall back on, so a single write forces a decision about the whole column. Designs differ on which one they take. Some refuse at that line, which is the outcome you can actually act on. Some re-infer the column and widen it to a representation that holds the new value, keeping every value intact. Some fall back to a representation storing one reference per row, which keeps the value and costs the typed pass. And some keep the representation and coerce the value into it — truncated, rounded, or reduced into the range — so the column looks untouched and holds a number nobody wrote. Knowing which of the four your stack does is the whole question.

go deeper

for a junior

Recall that a column stores every row in one form, so a value that does not fit cannot just sit in its own row. Something has to give, and it is the column, not the cell.

for a middle

Explain all four outcomes and what each costs: an error at the line, a wider column with a second buffer, a reference per row with no typed pass, or an unchanged column holding a changed number.

for a senior

Show that you know which outcome your own stack takes and how you established it, and that you treat the coercing case as a correctness problem rather than a tidiness one.

for a principal

The question for a team is whether writes into typed columns should be able to change them at all. Enforcement costs friction on every honest write and buys you that a wrong number cannot be created by an assignment.

## A write into a column is a decision about the column Start from a column that is doing its job: a **fixed-width numeric column**, where every row occupies the same declared number of bytes and a value outside that range simply has nowhere to live. A later step writes one value into one row, and the value does not fit — too large for the range, or not a number at all. Assume the write reached the column it named. The change cannot be confined to that row. A column is a single buffer in a single **column representation**, the one physical form every value in it is stored in. There is no per-row tag saying *this row is different*, so "store one value of another kind here" is not an operation the structure offers. Exactly one of a small set of things has to happen instead, and they are not equally visible. ## Four outcomes, and three of them keep running 1. **Refusal.** The write stops at that line with an error naming the column. Nothing downstream changes. This is the loud outcome, and for all that it feels obstructive it is the cheapest one to live with, because the fix is at the line that caused it. 2. **Widening.** The design re-infers the column on assignment and resolves it to a representation general enough for both the old values and the new one. Every value survives exactly. The costs are real but bounded: new bytes are written for the whole column, so the old buffer and the new one are both live during the step, and every row now pays the wider form. 3. **A fall back to the holder-for-anything representation.** The column becomes one reference per row, each row free to be a different kind of thing. No value is lost and nothing is reported. What is lost is the single typed pass: subsequent operations must establish each value's kind before acting on it. This is not a widening at all — it is the loss of the typed column, and it usually presents a week later as a step that has mysteriously slowed down. 4. **Coercion of the value into the existing representation.** The column keeps its representation, its width and its speed, and the value is made to fit — truncated of its fractional part, rounded, or reduced into the representable range. This is the quietest of the four, because from the outside nothing at all has changed, and the column now holds a number that nobody wrote. | outcome | column afterwards | value afterwards | how visible | |---|---|---|---| | refusal | unchanged | never stored | an error at that line | | widening | a more general representation | intact | nothing, unless you look at the representation | | fall back to holding anything | a reference per row | intact | nothing, until performance drops | | coercion | unchanged | changed | nothing at all | ## Why the quiet ones earn the interview time Outcomes two and three keep every value correct, so the harm is confined to cost: bytes, a second buffer, a lost typed pass. Outcome four does something different in kind — it produces a wrong number while leaving every observable property of the column identical. A report built on it is arithmetically consistent, internally plausible and wrong in one row, and there is no error, no warning and no change in the column's shape to point at. That is the split this whole subject turns on. The loud half of a type moving costs an hour of a developer's time. The half that keeps running costs whatever the wrong answer costs, discovered whenever somebody happens to check. ## Telling which one your design does The experiment is small enough to do while thinking about it: - Take a copy of a narrow whole-number column, write a value one past the top of its range into a single row, and read that row back. If you get an error, you are in outcome one. If the value reads back as written, check what the column is now made of to separate outcome two from outcome three. If the value reads back as a *different* number, you are in outcome four. - Repeat with a value of another kind entirely rather than an out-of-range number. Designs frequently handle the two cases differently: a too-large number is coerced while a value of the wrong kind is refused, or the reverse. - Note the answer somewhere your team can see it, because every later argument about how defensive to be at write time is really an argument about which of these four is in play. ## The claim to avoid The sentence that sounds right and is wrong is "a column that meets a value it cannot hold widens to a representation that can". It is true of designs that re-infer on assignment and false of designs that enforce the declared type and refuse, and it describes the fall back to holding anything as though it were a widening when it is the opposite — the abandonment of the typed column. Present the set, then say which member you are dealing with.

  • Why is coercing the value into the existing representation the most dangerous of the outcomes?
    Because it is the only one that changes a value while leaving every observable property of the column the same. The representation, the width and the speed are untouched, no error is raised, and the row now holds a number nobody wrote. The other three either stop at the line or keep the value intact and pay in bytes or speed.
  • Is a fall back to a representation that holds anything a kind of widening?
    No, and treating it as one is the common mistake. A widening moves the column to a more general typed form, so the values stay packed and operations stay a single pass. Falling back gives up the typed column entirely for one reference per row, so later operations must establish each value's kind first. The values survive either way; the cost profile does not.

saying these in an interview costs you the question

  • Believes only the written cell changes type.
  • Thinks a row can carry its own representation inside a column.
  • Assumes an out-of-range write always raises an error.
  • Says the column always widens to accommodate the value.
  • Calls a fall back to holding anything a widening.
  • Ignores that a coerced write stores a different number.