It crashed because we accessed lex->current_select when it was a NULL, which is the case for SP parameters or local variables.