|
7 | 7 | * |
8 | 8 | * |
9 | 9 | * IDENTIFICATION |
10 | | - * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.21 1999/05/25 16:09:46 momjian Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.22 1999/05/29 01:48:06 tgl Exp $ |
11 | 11 | * |
12 | 12 | *------------------------------------------------------------------------- |
13 | 13 | */ |
|
23 | 23 | #include"nodes/makefuncs.h" |
24 | 24 |
|
25 | 25 | #include"utils/builtins.h" |
| 26 | +#include"utils/syscache.h" |
26 | 27 | #include"utils/lsyscache.h" |
27 | 28 | #include"utils/palloc.h" |
28 | 29 | #include"parser/parse_type.h" |
@@ -286,80 +287,95 @@ replace_matching_resname(List *new_tlist, List *old_tlist) |
286 | 287 | staticList* |
287 | 288 | new_relation_targetlist(Oidrelid,Indexrt_index,NodeTagnode_type) |
288 | 289 | { |
289 | | -AttrNumberattno; |
290 | 290 | List*t_list=NIL; |
291 | | -char*attname; |
292 | | -inttyplen; |
293 | | -Oidatttype=0; |
294 | | -boolattisset= false; |
| 291 | +intnatts=get_relnatts(relid); |
| 292 | +AttrNumberattno; |
295 | 293 |
|
296 | | -for (attno=1;attno <=get_relnatts(relid);attno++) |
| 294 | +for (attno=1;attno <=natts;attno++) |
297 | 295 | { |
298 | | -attname=get_attname(relid,attno); |
299 | | -atttype=get_atttype(relid,attno); |
300 | | - |
301 | | -/* |
302 | | - * Since this is an append or replace, the size of any set |
303 | | - * attribute is the size of the OID used to represent it. |
304 | | - */ |
305 | | -attisset=get_attisset(relid,attname); |
306 | | -if (attisset) |
307 | | -typlen=typeLen(typeidType(OIDOID)); |
308 | | -else |
309 | | -typlen=get_typlen(atttype); |
| 296 | +HeapTupletp; |
| 297 | +Form_pg_attributeatt_tup; |
| 298 | +char*attname; |
| 299 | +Oidatttype; |
| 300 | +int32atttypmod; |
| 301 | +boolattisset; |
| 302 | + |
| 303 | +tp=SearchSysCacheTuple(ATTNUM, |
| 304 | +ObjectIdGetDatum(relid), |
| 305 | +UInt16GetDatum(attno), |
| 306 | +0,0); |
| 307 | +if (!HeapTupleIsValid(tp)) |
| 308 | +{ |
| 309 | +elog(ERROR,"new_relation_targetlist: no attribute tuple %u %d", |
| 310 | +relid,attno); |
| 311 | +} |
| 312 | +att_tup= (Form_pg_attribute)GETSTRUCT(tp); |
| 313 | +attname=pstrdup(att_tup->attname.data); |
| 314 | +atttype=att_tup->atttypid; |
| 315 | +atttypmod=att_tup->atttypmod; |
| 316 | +attisset=att_tup->attisset; |
310 | 317 |
|
311 | 318 | switch (node_type) |
312 | 319 | { |
313 | | -caseT_Const: |
| 320 | +caseT_Const:/* INSERT command */ |
314 | 321 | { |
315 | 322 | structvarlena*typedefault=get_typdefault(atttype); |
316 | | -inttemp=0; |
317 | | -Const*temp2= (Const*)NULL; |
318 | | -TargetEntry*temp3= (TargetEntry*)NULL; |
| 323 | +inttyplen; |
| 324 | +Const*temp_const; |
| 325 | +TargetEntry*temp_tle; |
319 | 326 |
|
320 | 327 | if (typedefault==NULL) |
321 | | -temp=0; |
| 328 | +typlen=0; |
322 | 329 | else |
323 | | -temp=typlen; |
324 | | - |
325 | | -temp2=makeConst(atttype, |
326 | | -temp, |
327 | | - (Datum)typedefault, |
328 | | -(typedefault== (structvarlena*)NULL), |
329 | | -/* XXX ? */ |
330 | | - false, |
331 | | - false,/* not a set */ |
332 | | - false); |
333 | | - |
334 | | -temp3=makeTargetEntry(makeResdom(attno, |
335 | | -atttype, |
336 | | --1, |
337 | | -attname, |
338 | | -0, |
339 | | - (Oid)0, |
340 | | - false), |
341 | | -(Node*)temp2); |
342 | | -t_list=lappend(t_list,temp3); |
| 330 | +{ |
| 331 | +/* |
| 332 | + * Since this is an append or replace, the size of |
| 333 | + * any set attribute is the size of the OID used to |
| 334 | + * represent it. |
| 335 | + */ |
| 336 | +if (attisset) |
| 337 | +typlen=get_typlen(OIDOID); |
| 338 | +else |
| 339 | +typlen=get_typlen(atttype); |
| 340 | +} |
| 341 | + |
| 342 | +temp_const=makeConst(atttype, |
| 343 | +typlen, |
| 344 | + (Datum)typedefault, |
| 345 | + (typedefault==NULL), |
| 346 | +/* XXX ? */ |
| 347 | + false, |
| 348 | + false,/* not a set */ |
| 349 | + false); |
| 350 | + |
| 351 | +temp_tle=makeTargetEntry(makeResdom(attno, |
| 352 | +atttype, |
| 353 | +-1, |
| 354 | +attname, |
| 355 | +0, |
| 356 | + (Oid)0, |
| 357 | + false), |
| 358 | + (Node*)temp_const); |
| 359 | +t_list=lappend(t_list,temp_tle); |
343 | 360 | break; |
344 | 361 | } |
345 | | -caseT_Var: |
| 362 | +caseT_Var:/* UPDATE command */ |
346 | 363 | { |
347 | | -Var*temp_var= (Var*)NULL; |
348 | | -TargetEntry*temp_list=NULL; |
| 364 | +Var*temp_var; |
| 365 | +TargetEntry*temp_tle; |
349 | 366 |
|
350 | | -temp_var=makeVar(rt_index,attno,atttype, |
351 | | -get_atttypmod(relid,attno), |
| 367 | +temp_var=makeVar(rt_index,attno,atttype,atttypmod, |
352 | 368 | 0,rt_index,attno); |
353 | 369 |
|
354 | | -temp_list=makeTargetEntry(makeResdom(attno, |
355 | | -atttype, |
356 | | -get_atttypmod(relid,attno), |
357 | | -attname, |
358 | | -0, |
359 | | -(Oid)0, |
360 | | -false), |
361 | | -(Node*)temp_var); |
362 | | -t_list=lappend(t_list,temp_list); |
| 370 | +temp_tle=makeTargetEntry(makeResdom(attno, |
| 371 | +atttype, |
| 372 | +atttypmod, |
| 373 | +attname, |
| 374 | +0, |
| 375 | + (Oid)0, |
| 376 | + false), |
| 377 | +(Node*)temp_var); |
| 378 | +t_list=lappend(t_list,temp_tle); |
363 | 379 | break; |
364 | 380 | } |
365 | 381 | default:/* do nothing */ |
|