           if( cols.len > 0 )
            {
                initStringInfo(&cols);
            } /*IF col.len>0*/

            if( query.len > 0 )
            {
                initStringInfo(&query);
            } /*IF col.len>0*/

            appendStringInfo( &query, "select a.attname from pg_class c,pg_attribute a where c.oid=%d AND a.attrelid = c.oid AND (", idxcd->reloid);

            for (i = 0; i < idxcd->ncols; ++i)
            {
                appendStringInfo( &cols, "%s a.attnum=%d", (i>0 ? " OR" : ""), idxcd->varattno[i]);

            }/* foreach col in varattno*/

            appendStringInfo( &cols, "%s", ")");

            /* FIXME: Mention the column names explicitly after the table name. */
            appendStringInfo( &query, "%s;", cols.data);

                int cont=0;                         
            if( query.len > 0 ) /* if we generated any SQL */
            {

                if( SPI_connect() == SPI_OK_CONNECT )
                {

                    ret=SPI_exec(query.data, 0);
                    proc=SPI_processed;
                    if( ret>0 )
                    {

                        if( SPI_tuptable != NULL)
                         {
                            TupleDesc tupdesc;
                            char buf[8192];
                            SPITupleTable *tuptable = SPI_tuptable;

                            tupdesc = tuptable->tupdesc;

                            int i,j;    
                            for(j=0;j<proc;j++)
                            {
                                HeapTuple tuple;
                                /*cada fila*/

                                tuple=tuptable->vals[j];    
                                if (tuple!=NULL)
                                {   
                                    for (i=1,buf[0]=0;i<=tupdesc->natts;i++)
                                    {
                                        char *data;

                                        /* cada columna de cada fila*/

                                        data=SPI_getvalue(tuple,tupdesc,i);
                                        idxcd->varattnombres[cont]=data;

                                        cont++;
                                        snprintf(buf + strlen (buf), sizeof(buf) - strlen(buf), " %s%s", SPI_getvalue(tuple, tupdesc, i),(i == tupdesc->natts) ? " " : " |");

                                    } /* (i=0,buf[0]=0;i<tupdesc->natts;i++)*/
                                    elog (INFO, "EXECQ: %s", buf);
                                } /* if (tuple!=null)*/
                                else
                                    elog( WARNING, "IND ADV: tuple is null." );
                        }   /* (j=0;j<proc;j++)*/
                    }   /*if( SPI_tuptable != NULL)*/
                    else
                        elog( WARNING, "IND ADV: SPI_tuptable is null." );
                }
                else    
                      elog( WARNING, "IND ADV: SPI_execute failed while select." );
                if( SPI_finish() != SPI_OK_FINISH )
                elog( WARNING, "IND ADV: SPI_finish failed while select." );

            } /*if( SPI_connect() == SPI_OK_CONNECT )*/         

            else
            elog( WARNING, "IND ADV: SPI_connect failed while select." );



            } /*if( query.len > 0 )*/
            elog (INFO, "if( query.len > 0");

            /*if( query.len > 0 )*/

    }   /* foreach cell in candidates */

    foreach( cell, candidates ) /* foreach cell in candidates */
    {

        idxcd = (IndexCandidate*)lfirst( cell );

        if (idxcd == NULL) {
                elog( INFO, "idxcd IS NULL" );
                   continue; /* Or is that fatal enough to break instead? */
                }

               if (!idxcd->idxused)
                 continue;

            int i;

            for (i = 0; i < idxcd->ncols; ++i)
            {
                elog(INFO,"i:%d", i);
                *elog(INFO,"varattnombres i:%s", idxcd->varattnombres[i]);*
                elog(INFO,"varattno i:%d", idxcd->varattno[i]);     
            }/* foreach col in varattno*/
    }
    /* TODO: Propose to -hackers to introduce API to free a StringInfoData . */
    if ( query.len > 0 )
        pfree( query.data );


    elog( DEBUG3, "IND ADV: select: EXIT" );
    return candidates;
}